Поделиться через


Using WPF's InPlaceBitmapMetadataWriter

Many folks have tried to use the WPF Imaging InPlaceBitmapMetadataWriter class without much success. Unfortunately the SDK sample provided only shows how to use this with PNG files... and this is less than ideal since folks are mainly interested in metadata on their JPEGs and TIFFs. The InPlaceBitmapMetadataWriter is a way to invoke WIC's IWICFastMetadataEncoder, or as we call it "the FME". Basically this is a way to add metadata to a file very quickly without re-encoding the file. However, this only works if the file has metadata padding in it. Padding is extra space that the metadata handler sets aside in the file for writing out metadata in the future. Say I want to change an author form "Robert Wlodarczyk" to "Robert A. Wlodarczyk". Since the length of the new string is longer, without padding the metadata handler can't squish this data in to the file without moving what's after the metadata. As shipped in Windows Vista and WPF 3.0, padding is only supported in IFD, EXIF, and XMP metadata formats. Generally cameras do not produce files with padding in it, so this must be added initially. So, you need to re-encode the file initially. Luckily the WIC JPEG CODEC is able to do this in a manner which does not cause the image to lose any quality. Since IFD, EXIF, and XMP live only in TIFFs, JPEGs, and HD Photo (or at least as was shipped), should only use the InPlaceBitmapMetadataWriter with TIFFs, JPEGs, HD Photo. tExT is also supported by the InPlaceBitmapMetadataWriter... and this is for PNGs. Within the Windows Vista, the property dialog and Photo Gallery both use the FME to write out metadata quickly. Upon the first metadata edit, padding is added so that each subsequent metadata update is faster than the first. Note, the sample only covers JPEG, but it can easily be adapted to TIFF or HD Photo.

If you've struggled with the InPlaceBitmapMetadataWriter and want to get the sample... grab it from here.

Comments

  • Anonymous
    August 19, 2007
    After a long day and night of coding, I released version 0.8.0.0 of my Flickr Metadata Synchr tool on