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.
source share