Updated Branches:
  refs/heads/master 87b81e53f -> e2047afa4

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.


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/commit/231b39d2
Tree: 
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/tree/231b39d2
Diff: 
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/diff/231b39d2

Branch: refs/heads/master
Commit: 231b39d2dc0b953472a17646a591cce1edf9d7af
Parents: dddce30
Author: macdonst <[email protected]>
Authored: Wed Jun 27 14:06:52 2012 -0400
Committer: macdonst <[email protected]>
Committed: Thu Jun 28 12:00:19 2012 -0400

----------------------------------------------------------------------
 .../src/org/apache/cordova/CameraLauncher.java     |   12 ++++++------
 framework/src/org/apache/cordova/ExifHelper.java   |    4 ++++
 2 files changed, 10 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/231b39d2/framework/src/org/apache/cordova/CameraLauncher.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/CameraLauncher.java 
b/framework/src/org/apache/cordova/CameraLauncher.java
index 5d1d2b6..4d21a9b 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;
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/231b39d2/framework/src/org/apache/cordova/ExifHelper.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/ExifHelper.java 
b/framework/src/org/apache/cordova/ExifHelper.java
index c4f7d91..4be79f1 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;
+    }
 }

Reply via email to