If you upload photos from your smartphone to a web page, they will be displayed incorrectly.
Because photos are stored by the smartphone with the rotation angle.
Therefore you have to rotate a photo automatically when importing.
To do this, you have to create an image (bitmap) from the upload file and then query the properties 0x0112
Image.GetPropertyItem(0x0112).Value[0];
|
Then you can rotate the picture
originalImage.RotateFlip(rotateFlipType: RotateFlipType.Rotate90FlipNone);
|
Asp.Net Core 2 MVC
//----< check Properties >---- Image originalImage = Image.FromFile(new_FullFilename_on_Server); if (originalImage.PropertyIdList.Contains(0x0112)) { int rotationValue = originalImage.GetPropertyItem(0x0112).Value[0]; switch (rotationValue) { case 1: // landscape, do nothing break;
case 8: // rotated 90 right // de-rotate: originalImage.RotateFlip(rotateFlipType: RotateFlipType.Rotate270FlipNone); originalImage.Save(new_FullFilename_on_Server); break;
case 3: // bottoms up originalImage.RotateFlip(rotateFlipType: RotateFlipType.Rotate180FlipNone); originalImage.Save(new_FullFilename_on_Server); break;
case 6: // rotated 90 left originalImage.RotateFlip(rotateFlipType: RotateFlipType.Rotate90FlipNone); originalImage.Save(new_FullFilename_on_Server); break; } } originalImage.Dispose(); //----</ check Properties >----
|
Reference: Code from CodeProject