Reading metadata from images in WPF

I know that WPF allows you to use images that require WIC codecs to view (for the sake of argument, say, a RAW file with a digital camera); however, I can only see that it allows you to display the image initially, but I do not see anyway the receipt of metadata (for example, exposure time).

Obviously, this can be done, as Windows Explorer shows, but it manifests itself through API.net or you think that this is just before calling the native COM interfaces.

+4
source share
2 answers

Check out my Intuipic project. In particular, the BitmapOrientationConverter class, which reads metadata to determine the image orientation:

using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read)) { BitmapFrame bitmapFrame = BitmapFrame.Create(fileStream, BitmapCreateOptions.DelayCreation, BitmapCacheOption.None); BitmapMetadata bitmapMetadata = bitmapFrame.Metadata as BitmapMetadata; if ((bitmapMetadata != null) && (bitmapMetadata.ContainsQuery(_orientationQuery))) { object o = bitmapMetadata.GetQuery(_orientationQuery); if (o != null) { //refer to http://www.impulseadventure.com/photo/exif-orientation.html for details on orientation values switch ((ushort) o) { case 6: return 90D; case 3: return 180D; case 8: return 270D; } } } } 
+9
source

Although WPF does provide these APIs, they are not very friendly, and they are not particularly fast. I suspect they do a lot.

I support a simple open source library for extracting metadata from images and videos. This is 100% C # without P / Invoke.

 // Read all metadata from the image var directories = ImageMetadataReader.ReadMetadata(stream); // Find the so-called Exif "SubIFD" (which may be null) var subIfdDirectory = directories.OfType<ExifSubIfdDirectory>().FirstOrDefault(); // Read the orientation var orientation = subIfdDirectory?.GetInt(ExifDirectoryBase.TagOrientation); switch (orientation) { case 6: return 90D; case 3: return 180D; case 8: return 270D; } 

In my tests, this is 17 times faster than the WPF API. If you want only Exif from JPEG, use the following and more than 30 times faster:

 var directories = JpegMetadataReader.ReadMetadata(stream, new[] { new ExifReader() }); 

Extractor metadata library is available through NuGet and GitHub code .

The loan falls to many participants who have helped the project since 2002.

+2
source

All Articles