I’m using the Upload control to have the user take a picture with the cell phone camera. When the user takes a photo in portrait orientation and uploads it, the control captures and sends a landscape image instead.
Is there a way to ensure the image uploaded is the same orientation as how the picture was taken with the camera?
This may have been my fault actually, because I did some post-processing on the image after it was uploaded.
You must read the EXIF property from the original Image/Bitmap, store that property, and then re-apply it to any “New” Bitmaps or Images you create.
//Properties
public PropertyItem EXIForientation;//will be used to save future .bmp
public ushort isoEXIForientation;//stores the int value for debugging
public CustomImageResizer(string strFilename)
{
// Create a bitmap of the content of the fileUpload control in memory
originalBMP = new Bitmap(strFilename);
//Read EXIF orientation
EXIForientation = this.originalBMP.GetPropertyItem(0x0112);//274 = orientation.
//1 = Horizontal, 3 = Rotate 180 degrees , 6 = Rotate 90 degrees clockwise, 8 = Rotate 270 degrees clockwise
isoEXIForientation = BitConverter.ToUInt16(EXIForientation.Value, 0);
}
//Reapply
//Create a new bitmap which that holds the previous resized bitmap
using (var newBMP = new Bitmap(originalBMP, newWidth, newHeight))
{
newBMP.SetPropertyItem(this.EXIForientation);//reapply orientation
** Note that it will still appear rotated incorrectly in WiseJ and .NET PictureBox controls, because they do respect EXIF orientation. Working on that next.
Yep, and one implementation on the javascript side can be seen here: https://stackoverflow.com/questions/19463126/how-to-draw-photo-with-correct-orientation-in-canvas-after-capture-photo-by-usin
I could also read the EXIF on Windows and perform a rotation there. However, I’m wondering if there is a way to catch this or fix this on the HTML5 specification side…. it blows my mind that the browser does not upload the photo with the same orientation that the picture is taken…
Hi Andrew,
not sure but this might be an Android issue. Common practice seems to be to read the exif data and rotate the image if necessary.
Best regards
Frank
Please login first to submit.