Out of box support for read and write Exif data on all platforms.
Description
Support Read and Write Exif Data for multiple types of images, including:
- HEIF/HEIC
- jpeg
- png
This will let us get metadata from captured or picked images or set some metadata tags ourselves.
There are a few library's out there which help in this but they have their own drawbacks. 2 of them which I looked into in more depth:
- ExifLibNet: Supports Read and Write but slow, doesn't support HEIC/HEIF images (ios image types) and not maintained now.
- Metadata-Extractor: Supports Read only (The maintainer is reluctant to add support for Write), supports all types of images and maintained frequently.
Currently I couldn't find support for this. PropertyItems is a class but it is only supported in Windows and not to full extent.
Public API Changes
To read an image file and extract metadata:
var file = ImageFile.FromFile("path_to_image");
// the type of the ISO speed rating tag value is unsigned short
// see documentation for tag data types
var isoTag = file.Properties.Get<ExifUShort>(ExifTag.ISOSpeedRatings);
// the flash tag's value is an enum
var flashTag = file.Properties.Get<ExifEnumProperty<Flash>>(ExifTag.Flash);
// GPS latitude is a custom type with three rational values
// representing degrees/minutes/seconds of the latitude
var latTag = file.Properties.Get<GPSLatitudeLongitude>(ExifTag.GPSLatitude);
To add metadata:
var file = ImageFile.FromFile("path_to_image");
// note the explicit cast to ushort
file.Properties.Set(ExifTag.ISOSpeedRatings, <ushort>200);
To save the image with metadata:
file.Save("path_to_image");
Taken from ExifLibNet: looks neat to me.
Intended Use-Case
In my application I have a huge requirement to get image metadata for some processing which includes but not limited to orientation, gps, focal-value etc. These tags are important for making some requests and doing some post-processing after taking/selecting an image.
There is also a case where I get values from some other sensors in my app when an Image is taken, and I would like to add those values to the Exif of the image
in the meantime, does anyone have any suggestions for the same? any libs, implementation I could look into.
We use https://www.nuget.org/packages/MetadataExtractor/ to read the exif data for orientation, not sure if it gives you everything you need but supports all the major image formats.