Howto SET image metadata (Tiff, geotiff, exif tags)

R

Robert Seidl

I saw that VB .Net 2003 has some tools for easily reading metadata
information present in some TIFF and JPG files, eg.
----------------------------------------------------------------
....
Dim b As New Bitmap(OpenFileDialog1.FileName)
For Each p As System.Drawing.Imaging.PropertyItem In b.PropertyItems
' do something with
' p.Id
' p.Len
' p.Type
' p.Value
Next
----------------------------------------------------------------

And this works nicely, you can google for some code on the web that parses
out EXIF tags, TIFF tags etc.

Now how about WRITING tags ? Much messier !
Acc to docs, there is no constructor for the PropertyItem class, so where do
you get an instance ?
Microsofts answer: you STEAL it. From an existing tag:

----------------------------------------------------------------
....
Dim b As New Bitmap(OpenFileDialog1.FileName)

Dim prop As System.Drawing.Imaging.PropertyItem = image.PropertyItems(0) '
steal this instance
Dim bvalue() As Byte = {0, 1, 2, 3}
prop.Id = 34264 '//set the id (Tag Number)
prop.Len = 4 'set the length
prop.Type = 2'//set the type (datatype)
prop.Value = bvalue '//set the value
image.SetPropertyItem(prop) '//apply the property to the image
----------------------------------------------------------------

I assume this will add rather than replace the existing (stolen)
propertyitem, as long as a different Id is used.
But what if I start with an image from scratch, eg.
----------------------------------------------------------------
Dim image As New Bitmap(200, 200,
System.Drawing.Imaging.PixelFormat.Format32bppPArgb)
....draw stuff into image
....now how to add a PropertyItem to image ????
----------------------------------------------------------------


I need to add GeoTIFF tags to bitmaps created from scratch in VB .net
....whats the recommended route ?

Thanks in advance
Robert
 
Top