I understand that this answer does not apply to the .NET framework v2, but I thought it was worth documenting for those of you who are using .NET 3.5 or higher. This may also work in version 3.0, but I did not test it there.
The following function call will return keywords embedded in the JPEG image:
private string[] GetKeywords(string filespec) { BitmapDecoder decoder = new JpegBitmapDecoder(new FileStream(filespec, FileMode.Open), BitmapCreateOptions.None, BitmapCacheOption.None); BitmapMetadata meta = (BitmapMetadata)decoder.Frames[0].Metadata; return meta.Keywords.ToArray<string>(); }
The BitmapDecoder and BitmapMetadata classes are contained in the assembly that is commonly used in WPF, so you will need to reference the following assemblies to use these classes:
- PresentationCore
- WindowsBase
I have successfully used this approach in a WinForm application, but I suspect that it may be adapted for other types of applications. In addition, you can see that the abstract class "BitmapDecoder" in this example is assigned an instance of JpegBitmapDecoder, but you can get an instance of another decoder for your image type (TIFF, GIF, PNG, BMP and WMP are also supported).
source share