C#, WPF and Bitmap Metadata

The central component to TagFlo is accessing the metadata stored in photos and adding additional descriptors. There are two big gotchas that crop up when you work with MetaData in WPF/NET 3.0

The first is that if you are trying to work with Metadata in a thread instead of the main application you have to set the apartment state to STA Thread. Since the image class uses graphics code, it likes to be in this type of thread. Not sure way, but when you add this line: Thread.SetApartmentState(ApartmentState.STA);your life will be easier. There is more information available here.

The other gotcha pops up when you are trying to add new metadata to a file. The metadata for a photo is stored right in the file, usually in the front. Often times there isn’t any extra space between the metadata and the start of the file, so you need to create some white space for the new data you want to add. There is a good method for doing that here.

The two stupid little things took me way to long to figure out. Problem solving is half the fun of programming though!

Leave a Reply