WPF BitmapImage complains about EXIF corrupt metadata

79 Views Asked by At

I am using a Image control to show/load images in WPF. My jpg images are exif files. My WPF program is complaining about corrupt exif metadata header and dont show that image in image control. There is no problem opening this image else where like in mspaint or in photos app or in browser etc.

I tried exiftool, and it says warning - malformed Exif APP1 segment

I tried to investigate more regarding APP1 segment format,

I open my image in hex, it says:

FF D8 FF E1 00 BC 45 78 69 66 00 00 49 01 01 2C 01 2C 00 00

Bytes in bold represents tiff header. tiff header first two bytes either should be 49 49 (Intel II) or 4d 4d (Motorolla)

What is 49 01 in my image? Is it the reason of corruption message?

My WPF program is breaking and not showing any image due to this. ExifTool is showing it as warning: malformed exif app1 segment.

Image is rendered fine everywhere else in browser, in mspaint or in any other imaging tool.

Need little help here.

I am using .NET framework 4.6.1, Also tried it in .NET 4.8 framework with same error.

1

There are 1 best solutions below

0
Rakesh Kumar On

Just to help anyone facing the similar problem,

I decided to ignore color profiles while creating Bitmap images in WPF. This will totally ignore validating any image header in WPF and all worked smooth

https://learn.microsoft.com/en-us/dotnet/api/system.windows.media.imaging.bitmapcreateoptions

Please note - It will also remove any color profile imformation while saving images back. So if you desparately need to maintain the color profiles for images, choose this option wisely.

Creating a service to check and fix the corrupt image headers using ExifTool can also be a way while you are trying to get bulk images from somewhere in system.