View property items for an image

Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
1 post Page 1 of 1
Contributors
User avatar
MrAksel
C# Coder
C# Coder
Posts: 1758
Joined: Fri Mar 26, 2010 12:27 pm

View property items for an image
MrAksel
To view various property items for an image, you can use the Image.PropertyItems to list every item available. One example could be
Code: Select all
For Each Item As PropertyItem In MyImage.PropertyItems
   MessageBox.Show(Item.Id & ": " & Item.Len & " bytes value.")
Next
There is a Value property for the PropertyItem structure, it is a byte array that contains the actual value. You can use the Type property together with the Value to get the actual value.
Code: Select all
Private Function GetValue(prop As PropertyItem) As Object
	Select Case prop.Type
		Case 1
			Return prop.Value(0)
		Case 2
			Return System.Text.Encoding.ASCII.GetString(prop.Value)
		Case 3
			Return BitConverter.ToUInt16(prop.Value, 0)
		Case 4
			Return BitConverter.ToUInt32(prop.Value, 0)
		Case 5
			Return New UInteger() {BitConverter.ToUInt32(prop.Value, 0), BitConverter.ToUInt32(prop.Value, 4)} 'URational class is not supported by .NET'
		Case 6
			Return CSByte(prop.Value(0))
		Case 7
			Return prop.Value(0) 'Undefined'
		Case 8
			Return BitConverter.ToInt16(prop.Value, 0)
		Case 9
			Return BitConverter.ToInt32(prop.Value, 0)
		Case 10
			Return New Integer() {BitConverter.ToInt32(prop.Value, 0), BitConverter.ToInt32(prop.Value, 4)} 'Rational class is not supported by .NET'
		Case 11
			Return BitConverter.ToSingle(prop.Value, 0)
		Case 12
			Return BitConverter.ToDouble(prop.Value, 0)
	End Select
	Return prop.Value
End Function
Then we can edit our first function to show the actual value too:
Code: Select all
For Each Item As PropertyItem In MyImage.PropertyItems
   MessageBox.Show(Item.Id & ": " & GetValue(Item).ToString())
Next
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;


Over 30 projects with source code!
Please give reputation to helpful members!

Image
Image
1 post Page 1 of 1
Return to “Tutorials”