by Marcel Wijnands
10. November 2008 00:46
I expected to find a lot of information and examples about reading and writing JPEG metadata when I started searching the net. However I couldn't find much. After finding a great blog entry by Robert A. Wlodarczyk I created a useful Class that can be used in both ASP.NET and Windows Forms / WPF applications. Please note I'm always using VB 9.0's type inference, I love it because it's less typing ;)
To read or write metadata to a JPEG, use the JpegMetaData's constructor to open the file;
Dim myMetaData = New JpegMetaData(Server.MapPath("Photo.jpg"))
My basic class supports only 5 properties, but you could extend it;
myMetaData.Title = "My Title"
myMetaData.Subject = "My Subject"
myMetaData.Rating = 4
myMetaData.Keywords = (New String() {"Keyword1", "Keyword2"}).ToList
myMetaData.Comments = "My Comments"
the metadata is not saved until the save function is called, which will return a boolean to indicate wether the save succeeded;
Dim isSaved = myMetaData.Save()
JpegMetaData can be downloaded below;
JpegMetaData.zip (1.71 kb)