从PictureBox控件获取图像文件名

时间:2016-01-21 03:16:20

标签: vb.net image title picturebox

我在文件夹中有一个图像,我可以通过以下方式显示在PictureBox上:

PictureBox1.Image = Nothing 'Clearing PictureBox1 
Dim bmPhotos as new Bitmap("C:\Photos\ImageName.gif")
PictureBox1.Image = bmPhotos

我想获得有关图像的其他信息。特别是图像标题。这有可能在.Net吗?

谢谢。

3 个答案:

答案 0 :(得分:0)

您可以使用 System.IO.Path System.IO.File 获取更多信息,如下所示:

System.IO.Path.GetFileName("ImagePathHere")
System.IO.Path.GetExtension("ImagePathHere")
System.IO.File.GetCreationTime("ImagePathHere")
System.IO.File.GetLastAccessTime("ImagePathHere")

只需浏览它,您就可以获得有关您文件的更多详细信息。

答案 1 :(得分:0)

Path.GetFileName Method (String):返回指定路径字符串的文件名和扩展名。

Path.GetFileNameWithoutExtension Method (String):返回没有扩展名的指定路径字符串的文件名。

 If PictureBox1.Location.ToString <> String.Empty Then
     Dim image_title, image_title1 As String
     'To get file name with extension : output=ImageName.gif
     image_title = Path.GetFileName(picImage.ImageLocation)

     'To get file name without extension : output=ImageName
     image_title1 = Path.GetFileNameWithoutExtension(picImage.ImageLocation)
 End If

答案 2 :(得分:0)

如果您想要阅读图像元数据,如标题,作者,相机制作,模型等,它们将作为EXIF存储在图像标题中。

可以使用PropertyItems检索它们。 每个属性标记都以十六进制值标识,您可以找到它们herehere

'Create an Image object. 
Dim img As Image = Image.FromFile("C:\Ashish\apple.jpg")

'Get the PropertyItems property from image.
Dim propItems As PropertyItem() = img.PropertyItems

Dim encoding As New System.Text.ASCIIEncoding()

Dim title As String = encoding.GetString(propItems(0).Value)
Dim manufacturer As String = encoding.GetString(propItems(1).Value)

读取EXIF元数据的一个非常简单的实现是available here

enter image description here

相关问题