I have a PictureBox in .Net that displays images from a folder "Photos" using the following code on a click event:
我在.Net中有一个PictureBox,它在点击事件中使用以下代码显示“Photos”文件夹中的图像:
PictureBox1.Image = Nothing 'Clearing PictureBox1
Dim bmPhotos as new Bitmap("C:\Photos\ImageName.gif")
PictureBox1.Image = bmPhotos
I want to replace "ImageName" in the file path with the name of the last captured image programatically. Is there a way to find out the name of the image that was added last to the "Photos" folder?
我想以编程方式将文件路径中的“ImageName”替换为最后捕获的图像的名称。有没有办法找出最后添加到“照片”文件夹的图像的名称?
Thank you.
谢谢。
1 个解决方案
#1
0
If the last created file is what you need, you can find it this way:
如果最后创建的文件是您需要的,您可以通过以下方式找到它:
Dim file = System.IO.Directory.GetFiles("path") _
.OrderByDescending(Function(f) New System.IO.FileInfo(f).CreationTime) _
.FirstOrDefault()
You can also use GetFiles("path", "*.gif")
to limit the result between gif files.
您还可以使用GetFiles(“path”,“* .gif”)来限制gif文件之间的结果。
Also you can add some criteria after GetFiles
, to limit the file types to be between specific file types, for example:
您还可以在GetFiles之后添加一些条件,以将文件类型限制在特定文件类型之间,例如:
.Where(Function(f) New String() {".gif", ".png"}.Contains(System.IO.Path.GetExtension(f)))
Then you can show the image this way:
然后你可以这样显示图像:
Me.PictureBox1.ImageLocation = file
Or
要么
Me.PictureBox1.Load(file)
#1
0
If the last created file is what you need, you can find it this way:
如果最后创建的文件是您需要的,您可以通过以下方式找到它:
Dim file = System.IO.Directory.GetFiles("path") _
.OrderByDescending(Function(f) New System.IO.FileInfo(f).CreationTime) _
.FirstOrDefault()
You can also use GetFiles("path", "*.gif")
to limit the result between gif files.
您还可以使用GetFiles(“path”,“* .gif”)来限制gif文件之间的结果。
Also you can add some criteria after GetFiles
, to limit the file types to be between specific file types, for example:
您还可以在GetFiles之后添加一些条件,以将文件类型限制在特定文件类型之间,例如:
.Where(Function(f) New String() {".gif", ".png"}.Contains(System.IO.Path.GetExtension(f)))
Then you can show the image this way:
然后你可以这样显示图像:
Me.PictureBox1.ImageLocation = file
Or
要么
Me.PictureBox1.Load(file)