From 7a0885d255a46c93a83e808344f5f88c3c14c6d1 Mon Sep 17 00:00:00 2001 From: Tim Mickel Date: Mon, 11 Jan 2016 13:30:56 -0500 Subject: [PATCH] Rotate Android images to account for JPEG rotations --- .../main/java/org/scratchjr/android/CameraView.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/android/ScratchJr/app/src/main/java/org/scratchjr/android/CameraView.java b/android/ScratchJr/app/src/main/java/org/scratchjr/android/CameraView.java index 6e61db1..050c718 100644 --- a/android/ScratchJr/app/src/main/java/org/scratchjr/android/CameraView.java +++ b/android/ScratchJr/app/src/main/java/org/scratchjr/android/CameraView.java @@ -179,12 +179,12 @@ public class CameraView /** * Take the given bitmap image from the camera and transform it to the correct - * aspect ratio and size. + * aspect ratio, size, and rotation. * * @return jpeg-encoded data of the transformed image. */ - public byte[] getTransformedImage(Bitmap originalImage) { - Bitmap cropped = cropAndResize(originalImage); + public byte[] getTransformedImage(Bitmap originalImage, int exifRotation) { + Bitmap cropped = cropResizeAndRotate(originalImage, exifRotation); ByteArrayOutputStream bos = new ByteArrayOutputStream(); cropped.compress(CompressFormat.JPEG, 90, bos); try { @@ -202,7 +202,7 @@ public class CameraView * * If the image was front-facing, also mirror horizontally. */ - private Bitmap cropAndResize(Bitmap image) { + private Bitmap cropResizeAndRotate(Bitmap image, int exifRotation) { int imageWidth = image.getWidth(); int imageHeight = image.getHeight(); float rectWidth = _rect.width(); @@ -220,6 +220,8 @@ public class CameraView } Matrix m = new Matrix(); + // Adjust the image to undo rotation done by JPEG generator + m.postRotate(-1.0f * exifRotation); if (_currentFacingFront) { // flip bitmap horizontally since front-facing camera is mirrored m.preScale(-1.0f, 1.0f);