Photo taken from iphone gets rotated 90 degrees on Android phone

  • Thread starter Thread starter Android Central Question
  • Start date Start date
A

Android Central Question

Scenario : The photo rotated 90 degrees when the picture was taken from the iPhone camera and uploaded on the server and trying to load the same photo on android device.

What I found so far is Meta information(EXIF data) is ignored by the Android system before downloading the image. When photo uploaded from iPhone, the EXIF information of that particular photo is something like this: orientation 6 Rotated 90 CCW, but when it comes to android this value becomes: orientation 0(UNDEFINED)

I tried a couple of approaches but did not work, let me know if anyone faced similar issue or any solution or work around for this, Thanks in advance.

BitmapFactory.Options bmOptions = new BitmapFactory.Options();
bmOptions.inSampleSize = 4;
resultBitmap = decodeStream(inputStream, null, bmOptions);
ExifInterface exif = new ExifInterface(inputStream);
String orientString = exif.getAttribute(ExifInterface.TAG_ORIENTATION);
int orientation = orientString != null ? Integer.parseInt(orientString) : ExifInterface.ORIENTATION_NORMAL;
int rotationAngle = 0;
if (orientation == ExifInterface.ORIENTATION_ROTATE_90) rotationAngle = 90;
else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) rotationAngle = 180;
else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) rotationAngle = 270;
Matrix matrix = new Matrix();
matrix.setRotate(rotationAngle);
Bitmap rotated = Bitmap.createBitmap(resultBitmap,0,0,resultBitmap.getWidth(),resultBitmap.getHeight(),matrix,true);
if(rotated != null){
resultBitmap = rotated;
}
 
The EXIF data is getting removed from the image, thus causing orientation problems, as you have discovered.
The trick is finding out where the EXIF data is getting removed and correcting that problem.
Unfortunately, some services like Facebook purposely remove the EXIF data to make it easier to steal the photos.

If you are looking for a programming fix in your app, you will probably want this thread moved to one of the developer forums.
 

Trending Posts

Forum statistics

Threads
956,861
Messages
6,970,386
Members
3,163,644
Latest member
RichardDixon