獲取圖像文件名我有一個形象,這我能夠通過以下方式來顯示到一個PictureBox的文件夾中:從PictureBox控件
PictureBox1.Image = Nothing 'Clearing PictureBox1
Dim bmPhotos as new Bitmap("C:\Photos\ImageName.gif")
PictureBox1.Image = bmPhotos
我想獲得關於圖像的附加信息。具體是圖片標題。在.Net中可以這樣做嗎?
謝謝。
獲取圖像文件名我有一個形象,這我能夠通過以下方式來顯示到一個PictureBox的文件夾中:從PictureBox控件
PictureBox1.Image = Nothing 'Clearing PictureBox1
Dim bmPhotos as new Bitmap("C:\Photos\ImageName.gif")
PictureBox1.Image = bmPhotos
我想獲得關於圖像的附加信息。具體是圖片標題。在.Net中可以這樣做嗎?
謝謝。
如果要讀取標題,作者,相機制作,模型等圖像元數據,它們將作爲EXIF存儲在圖像標題中。
它們可以通過使用PropertyItems來檢索。 每個屬性標籤都由一個十六進制值標識,您可以找到它們here和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。
可以使用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)
:返回指定路徑字符串的文件名和擴展名。
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
阿希什,我通過propItems的所有元件和環的類型是所述第六元件。非常感謝你。 –