vb.net 从 PictureBox 控件中获取图像文件名

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34914790/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 19:41:34  来源:igfitidea点击:

Get image file name from PictureBox control

vb.netimagetitlepicturebox

提问by Alc

I have an image in a folder which I am able to display onto a PictureBox in the following manner:

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

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

I would like to obtain additional information about the image. Specifically the image Title. Is that possible to do in .Net?

我想获取有关图像的其他信息。特别是图像标题。在 .Net 中可以这样做吗?

Thank you.

谢谢你。

采纳答案by Ashish Emmanuel

If you want to read the image metadata such as Title, Author, Camera Make, Model, etc., They are stored in the Image Header as EXIF.

如果要读取图像元数据,如标题、作者、相机制造商、型号等,它们作为 EXIF 存储在图像标题中。

They can be retrieved by using PropertyItems. Every Property Tag is identified by a hexadecimal value and you can find them hereand here.

可以使用PropertyItems检索它们。每个属性标签都由一个十六进制值标识,您可以在此处此处找到它们。

'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)

A very simple implementation to read EXIF metadata is available here.

一个非常简单的实现读取EXIF元数据可以在这里找到

enter image description here

在此处输入图片说明

回答by Allen Binuya

You can get additional information using System.IO.Pathand System.IO.Filelike these:

您可以使用System.IO.PathSystem.IO.File获取其他信息,如下所示:

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

Just explore it and you can get more details about your file.

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

回答by Vivek S.

Path.GetFileName Method (String): Returns the file name and extension of the specified path string.

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

Path.GetFileNameWithoutExtension Method (String): Returns the file name of the specified path string without the extension.

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