Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set JPEG metadata - implementation problems

Through prior research, I've found that is isn't too hard to set the MetaData properties on an image. For example, I can read a JPEG image into a Bitmap object and change its "Original Taken" date through the image's SetPropertyItem method (I've already researched the format and enumeration for doing this, too).

However, although the actual MetaData part seems easy, I am faced with a couple of irritating implementation issues:

1) When I call Save() on the bitmap, it doesn't seem that the image's original encoding settings are used. As a result, the compression level changes (presumably to some default value); I can see the file size shrink considerably after my Save() call. I know that you can customize the encoding settings for an image within the call to Save(), but honestly, I only want to change the picture's metadata; isn't there any easy way to just save the image using its original encoding settings? Even if I could directly reference the image's existing encoding settings in the Save() call, that would help.

2) Apparently, the original file is locked when you read it into a Bitmap object. As a result, I can't save the image under its original file name without a lot of messing around: currently, I'm drawing the image I read from file onto an offscreen bitmap, disposing of the original image, and then saving the offscreen bitmap. Again, this seems like an awful lot of extra work when all I want to do is update the metadata in an image file.

Any suggestions you can offer would be most appreciated... the amount of work I'm having to do just to update a JPEG file's meta data (most of which has nothing to do with the actual metadata change) leads me to wonder if I'm missing some easier or better ways of doing this.

like image 622
Brandon Amoroso Avatar asked Feb 14 '11 17:02

Brandon Amoroso


1 Answers

What you want to do is edit the EXIF data. What you are doing now is recompressing the image, and this will cause quality loss, as you have noticed.

See this code sample for editing EXIF: http://www.dreamincode.net/code/snippet3144.htm

like image 103
Brad Avatar answered Oct 02 '22 14:10

Brad