From 231b39d2dc0b953472a17646a591cce1edf9d7af Mon Sep 17 00:00:00 2001 From: macdonst Date: Wed, 27 Jun 2012 14:06:52 -0400 Subject: [PATCH] Reset orientation exif information when photo is rotated When a photo is taken in portrait mode we rotate it so it shows up properly in the webview. The Exif orientation must be reset to normal orientation (0) or the image will not display properly on desktops. --- framework/src/org/apache/cordova/CameraLauncher.java | 12 ++++++------ framework/src/org/apache/cordova/ExifHelper.java | 4 ++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/framework/src/org/apache/cordova/CameraLauncher.java b/framework/src/org/apache/cordova/CameraLauncher.java index 5d1d2b6e..4d21a9b5 100755 --- a/framework/src/org/apache/cordova/CameraLauncher.java +++ b/framework/src/org/apache/cordova/CameraLauncher.java @@ -265,6 +265,7 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie if (this.encodingType == JPEG) { exif.createInFile(DirectoryManager.getTempDirectoryPath(this.cordova.getActivity()) + "/.Pic.jpg"); exif.readExifData(); + rotate = exif.getOrientation(); } } catch (IOException e) { e.printStackTrace(); @@ -280,9 +281,8 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie if (destType == DATA_URL) { bitmap = getScaledBitmap(FileUtils.stripFileProtocol(imageUri.toString())); - rotate = exif.getOrientation(); if (rotate != 0) { - bitmap = getRotatedBitmap(rotate, bitmap); + bitmap = getRotatedBitmap(rotate, bitmap, exif); } this.processPicture(bitmap); @@ -303,16 +303,15 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie } // If all this is true we shouldn't compress the image. - if (this.targetHeight == -1 && this.targetWidth == -1 && this.mQuality == 100) { + if (this.targetHeight == -1 && this.targetWidth == -1 && this.mQuality == 100 && rotate == 0) { writeUncompressedImage(uri); this.success(new PluginResult(PluginResult.Status.OK, uri.toString()), this.callbackId); } else { bitmap = getScaledBitmap(FileUtils.stripFileProtocol(imageUri.toString())); - rotate = exif.getOrientation(); if (rotate != 0) { - bitmap = getRotatedBitmap(rotate, bitmap); + bitmap = getRotatedBitmap(rotate, bitmap, exif); } // Add compressed version of captured image to returned media store Uri @@ -450,7 +449,7 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie * @param bitmap * @return rotated bitmap */ - private Bitmap getRotatedBitmap(int rotate, Bitmap bitmap) { + private Bitmap getRotatedBitmap(int rotate, Bitmap bitmap, ExifHelper exif) { Matrix matrix = new Matrix(); if (rotate == 180) { matrix.setRotate(rotate); @@ -458,6 +457,7 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie matrix.setRotate(rotate, (float) bitmap.getWidth() / 2, (float) bitmap.getHeight() / 2); } bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); + exif.resetOrientation(); return bitmap; } diff --git a/framework/src/org/apache/cordova/ExifHelper.java b/framework/src/org/apache/cordova/ExifHelper.java index c4f7d91e..4be79f1f 100644 --- a/framework/src/org/apache/cordova/ExifHelper.java +++ b/framework/src/org/apache/cordova/ExifHelper.java @@ -178,4 +178,8 @@ public class ExifHelper { return 0; } } + + public void resetOrientation() { + this.orientation = "" + ExifInterface.ORIENTATION_NORMAL; + } }