Create PropertyItem() for image metadata (Tiff, geotiff, exif tags)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cgritton
    • Feb 2008
    • 1

    Create PropertyItem() for image metadata (Tiff, geotiff, exif tags)

    I have seen this question posted alot and have never seen a solution posted. This method will create a property item to set on a newly created bitmap. I figured this out quite some time ago and thought I'd share this handy little method. Hope it will help somebody trying to learn how to use property items for storing data with an image.

    VB.NET 2003, 2005, 2008

    [CODE=vbnet]
    'create a new property item for use with a new bitmap
    'that does not have property items
    Public Function CreatePropertyI tem() As System.Drawing. Imaging.Propert yItem

    'create a new bitmap (only 10x10 to minimize memory usage)
    Dim bmpProps As New Bitmap(10, 10)

    'create a new memory stream for manipulating the new bitmap
    Dim propMS As New IO.MemoryStream

    'new image is saved to stream with tiff format to create property items
    bmpProps.Save(p ropMS, System.Drawing. Imaging.ImageFo rmat.Tiff)

    'set the stream back to the beginning so we can read it out
    propMS.Position = 0

    'recreate bitmap from stream so we
    'should now have available property items
    bmpProps = Bitmap.FromStre am(propMS)


    If bmpProps.Proper tyItems.Length > 0 Then
    Return bmpProps.Proper tyItems(0)
    End If

    'should check for null when using
    'this function just in case something wierd happened
    Return Nothing
    End Function
    [/CODE]
    Last edited by debasisdas; Feb 7 '08, 12:07 PM. Reason: added code=vbnet tags
Working...