question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

IImage implementations drop all EXIF info from JPG files

See original GitHub issue

Processing images using IImage drops EXIF info from JPG files.

The attributes are dropped just when converter to Bitmap (any implementation of IImage) because Bitmap doesn’t store these properties. The problem is visible later when the Bitmap is exported.

This means that e.g. rotation of portrait jpg photos, gps coordinates of the photo, date of creation, used hardware and software (camera or phone model) and much more are lost.

Issue demonstrating what happens with portait photos opened and saved using IImage on Android (downsized but also not downsized, just plain loaded and exported using IImage): https://github.com/dotnet/maui/issues/6915

The issue is also present in Android.Graphics.Bitmap

This means that calling IImage.Resize or IImage.Downsize will drop all Exif properties -> this happens when the image is loaded as Bitmap -> the Exif info is dropped.

This means that when capturing a photo in portrait and then displaying a miniature of it, it is wrongly rotated when the miniature is exported using Maui graphics.

These Exif properties should be copied into the exported JPG file. However not all. There are Exif properties for date of creation, date of modificaion, width and height etc which change when the image is resized. So plain copying of the properties is not a solution.

https://docs.microsoft.com/en-us/dotnet/api/android.media.exifinterface?view=xamarin-android-sdk-12 This class doesn’t work at all when loading or saving from/to stream (e.g. byte[] converted to MemoryStream). Especially saving exif properties is not possible due to the fact that the underlying Java implementation treats the stream as InputStream and thus writing to it is not permitted despite the fact, that SaveAttributes method is available for Stream.

The class AndroidX.ExifInterface.Media.ExifInterface class which can be also used in MAUI, is capable of reading the properties (one by one, which is not straightforward). But is again not capable of saving them with the same issue as Android.Media.Exifinterface class

Will there be any support for this crucial feature of JPG processing? Without it, any JPG processed using Maui.Graphics is potentially not working as expected because part of JPG life is its metadata unlike PNG which is displayed fine without such metadata. However photos from users are not PNG.

My results on this:

Android.Media.ExifInterface cannot read from MemoryStream Android.Media.ExifInterface cannot save to MemoryStream AndroidX.ExifInterface.Media.ExifInteface can read from MemoryStream AndroidX.ExifInterface.Media.ExifInteface cannot save info memorystream because it treats it as java.InputStream https://stackoverflow.com/questions/41586663/android-exifinterface-not-saving-attribute ExifLib (NuGet ExifLib.PCL) reads basix Exif properties well but cannot save Exif data because there is no API to save

ExifLibNet extracts and saves exif info but this functionality should come out of the box in MAUI Graphics. Doing it manually is not so straightforward as simple copying of them all from the source file (e.g. when resizing the image):

These Exif properties should be copied into the exported JPG file. However not all. There are Exif properties for date of creation, date of modificaion, width and height etc which change when the image is resized. So plain copying of the properties is not a solution.

Example Exif properties loaded from a JPG image taken with Sony Xperia 5 phone using ExifLibNet:

[0:] Make Sony
[0:] Model J9210
[0:] Orientation RotatedLeft
[0:] XResolution 72/1
[0:] YResolution 72/1
[0:] ResolutionUnit Inches
[0:] Software 55.2.A.4.332_0_0
[0:] DateTime 08.05.2022 0:03:19
[0:] YCbCrPositioning Centered
[0:] EXIFIFDPointer 212
[0:] GPSIFDPointer 36352
[0:] ExposureTime 1/16
[0:] FNumber 8/5
[0:] ISOSpeedRatings 200
[0:] ExifVersion 0231
[0:] DateTimeOriginal 08.05.2022 0:03:19
[0:] DateTimeDigitized 08.05.2022 0:03:19
[0:] 236880 +02:00
[0:] 236881 +02:00
[0:] 236882 +02:00
[0:] ComponentsConfiguration System.Byte[]
[0:] ShutterSpeedValue 4/1
[0:] ExposureBiasValue 0/1
[0:] MeteringMode Pattern
[0:] LightSource Unknown
[0:] Flash AutoMode
[0:] FocalLength 213/50
[0:] MakerNote System.Byte[]
[0:] SubSecTime 101234
[0:] SubSecTimeOriginal 101234
[0:] SubSecTimeDigitized 101234
[0:] FlashpixVersion 0100
[0:] ColorSpace sRGB
[0:] PixelXDimension 4032
[0:] PixelYDimension 3024
[0:] InteroperabilityIFDPointer 36322
[0:] CustomRendered NormalProcess
[0:] ExposureMode Auto
[0:] WhiteBalance Auto
[0:] DigitalZoomRatio 1/1
[0:] SceneCaptureType Standard
[0:] SubjectDistanceRange Unknown
[0:] InteroperabilityIndex R98
[0:] InteroperabilityVersion 0100
[0:] ThumbnailCompression JPEG
[0:] ThumbnailOrientation RotatedLeft
[0:] ThumbnailXResolution 72/1
[0:] ThumbnailYResolution 72/1
[0:] ThumbnailResolutionUnit Inches
[0:] ThumbnailJPEGInterchangeFormat 36464
[0:] ThumbnailJPEGInterchangeFormatLength 3685

Example from Nokia XR 20 (portrait orientation image):

[0:] JFIFVersion 257
[0:] JFIFUnits None
[0:] XDensity 1
[0:] YDensity 1
[0:] JFIFXThumbnail 0
[0:] JFIFYThumbnail 0
[0:] JFIFThumbnail ExifLibrary.JFIFThumbnail
[0:] Model Nokia XR20
[0:] ImageWidth 3000
[0:] ImageLength 4000
[0:] DateTime 10.05.2022 17:51:14
[0:] Orientation RotatedLeft
[0:] EXIFIFDPointer 152
[0:] GPSIFDPointer 813
[0:] Make HMD Global
[0:] FNumber 179/100
[0:] ExposureTime 8333/500000
[0:] SubSecTimeDigitized 157
[0:] 236882 +02:00
[0:] SubSecTimeOriginal 157
[0:] 236881 +02:00
[0:] SubSecTime 157
[0:] 236880 +02:00
[0:] FocalLength 237/50
[0:] Flash FlashDidNotFire
[0:] ISOSpeedRatings 150
[0:] DateTimeDigitized 10.05.2022 17:51:14
[0:] DateTimeOriginal 10.05.2022 17:51:14
[0:] PixelYDimension 4000
[0:] WhiteBalance Auto
[0:] PixelXDimension 3000
[0:] ApertureValue 167/100
[0:] ShutterSpeedValue 2953/500
[0:] ExifVersion 0220
[0:] MakerNote System.Byte[]
[0:] GPSLatitudeRef North
[0:] GPSLatitude ExifLibrary.MathEx+UFraction32[]
[0:] GPSLongitudeRef East
[0:] GPSLongitude ExifLibrary.MathEx+UFraction32[]
[0:] GPSAltitude 335/1
[0:] GPSTimeStamp ExifLibrary.MathEx+UFraction32[]
[0:] GPSDateStamp 10.05.2022 0:00:00

Edit: stuff like these is possible in System.Drawing even in .NET Framework. Using PropertyItem (Image.GetPropertyItem and Image.SetPropertyItem) with ease.

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:4
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
StuffOfInterestcommented, May 29, 2022

Is there any plan to add EXIF support directly to MAUI Graphics? I have code that works with the System.Drawing.Image.PropertyItems collection to extract details after an image has been loaded into memory. If a third party library has to be used for extracting these details the efficiency of any consuming code goes down.

0reactions
msftbot[bot]commented, May 19, 2023

We’ve added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

Read more comments on GitHub >

github_iconTop Results From Across the Web

IImage implementations drop all EXIF info from JPG files
Processing images using IImage drops EXIF info from JPG files. The attributes are dropped just when converter to Bitmap (any implementation ...
Read more >
How to strip metadata from image files
Delete all JPEG sections that aren't necessary for rendering the image. Strips any metadata that various applications may have left in the ...
Read more >
c# - Easy way to clean metadata from an image?
Remove all metadata from common image formats? 1 · How to remove metadata from jpg and png images · 6 · Extract image...
Read more >
How to remove metadata from your photos
Windows allows you to remove EXIF metadata from single or multiple image files. Here are the steps: ... Right-click and select Properties, then ......
Read more >
How to delete all timestamp values in a JPG?
I know that aqlso there are a lot of different timestamps in the metadata; just looking into one with Opanda, I find four,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found