从 PictureBox 控件获取图像文件名
Get image file name from PictureBox control
我的文件夹中有一张图片,我可以通过以下方式将其显示在 PictureBox 上:
PictureBox1.Image = Nothing 'Clearing PictureBox1
Dim bmPhotos as new Bitmap("C:\Photos\ImageName.gif")
PictureBox1.Image = bmPhotos
我想获取有关图片的更多信息。特别是图像标题。在 .Net 中可以这样做吗?
谢谢。
您可以使用 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")
只需探索它,您就可以获得有关您的文件的更多详细信息。
Path.GetFileName Method (String)
: Returns指定路径字符串的文件名和扩展名。
Path.GetFileNameWithoutExtension Method (String)
:Returns指定路径字符串的文件名不带扩展名
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
如果您想读取图像元数据,例如标题、作者、相机品牌、型号等,它们以 EXIF 形式存储在图像 Header 中。
可以使用 PropertyItems 检索它们。
每个 属性 标签都由一个十六进制值标识,您可以找到它们 here and here.
'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。
我的文件夹中有一张图片,我可以通过以下方式将其显示在 PictureBox 上:
PictureBox1.Image = Nothing 'Clearing PictureBox1
Dim bmPhotos as new Bitmap("C:\Photos\ImageName.gif")
PictureBox1.Image = bmPhotos
我想获取有关图片的更多信息。特别是图像标题。在 .Net 中可以这样做吗?
谢谢。
您可以使用 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")
只需探索它,您就可以获得有关您的文件的更多详细信息。
Path.GetFileName Method (String)
: Returns指定路径字符串的文件名和扩展名。
Path.GetFileNameWithoutExtension Method (String)
:Returns指定路径字符串的文件名不带扩展名
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
如果您想读取图像元数据,例如标题、作者、相机品牌、型号等,它们以 EXIF 形式存储在图像 Header 中。
可以使用 PropertyItems 检索它们。 每个 属性 标签都由一个十六进制值标识,您可以找到它们 here and here.
'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。