This would result in out of memory exception in some cases, can anyone tell me why is it happening and what would be the easiest workaround?
Asked
Active
Viewed 1,278 times
2
-
1Easiest fix seems like restricting portrait type images and and force landscapes – Raimonds Sep 20 '17 at 14:17
-
1Its likely that there is some form of rotation flag somewhere which isnt being honored – BugFinder Sep 20 '17 at 14:27
-
Maybe this post helps you : https://stackoverflow.com/questions/6222053/problem-reading-jpeg-metadata-orientation – Spongebrot Sep 20 '17 at 15:03
-
Opening image in gimp moans about EXIF data, so most likely solution will be in that post. Thanks for guidance – Raimonds Sep 20 '17 at 15:34
1 Answers
4
Just in case any other community member needs it, you can just simply access to image properties and check for the value on the id element 274. If you want to know quite more about this issue refer to Problem reading JPEG Metadata (Orientation) which helped me a lot while I was solving this.
This may not solve the width/height issue in a very good way, but at least the orientation of the picture will be ok.
using(var image = new Bitmap(filePath))
{
PropertyItem propertie = image.PropertyItems.FirstOrDefault(p => p.Id == 274);
if (propertie != null)
{
int orientation = propertie.Value[0];
if (orientation == 6)
image.RotateFlip(RotateFlipType.Rotate90FlipNone);
if (orientation == 8)
image.RotateFlip(RotateFlipType.Rotate270FlipNone);
}
}
-
Marking as Answer since it links to post which I used (also in comments) and it solved my issue. – Raimonds Oct 21 '19 at 10:40