diff options
-rw-r--r-- | src/com/android/camera/PhotoModule.java | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/src/com/android/camera/PhotoModule.java b/src/com/android/camera/PhotoModule.java index 2a902e22e..5aa7a57ae 100644 --- a/src/com/android/camera/PhotoModule.java +++ b/src/com/android/camera/PhotoModule.java @@ -1262,10 +1262,14 @@ public class PhotoModule extends BaseModule<PhotoUI> implements } } - private byte[] flipJpeg(byte[] jpegData) { + private byte[] flipJpeg(byte[] jpegData, int orientation) { Bitmap srcBitmap = BitmapFactory.decodeByteArray(jpegData, 0, jpegData.length); Matrix m = new Matrix(); - m.preScale(-1, 1); + if(orientation == 270) { + m.preScale(-1, 1); + } else { //if it's 90 + m.preScale(1, -1); + } Bitmap dstBitmap = Bitmap.createBitmap(srcBitmap, 0, 0, srcBitmap.getWidth(), srcBitmap.getHeight(), m, false); dstBitmap.setDensity(DisplayMetrics.DENSITY_DEFAULT); int size = dstBitmap.getWidth() * dstBitmap.getHeight(); @@ -1275,6 +1279,18 @@ public class PhotoModule extends BaseModule<PhotoUI> implements return outStream.toByteArray(); } + public static byte[] addExifTags(byte[] jpeg, int orientationInDegree) { + ExifInterface exif = new ExifInterface(); + exif.addOrientationTag(orientationInDegree); + ByteArrayOutputStream jpegOut = new ByteArrayOutputStream(); + try { + exif.writeExif(jpeg, jpegOut); + } catch (IOException e) { + Log.e(TAG, "Could not write EXIF", e); + } + return jpegOut.toByteArray(); + } + private final class JpegPictureCallback implements CameraPictureCallback { Location mLocation; @@ -1415,9 +1431,8 @@ public class PhotoModule extends BaseModule<PhotoUI> implements .findPreference(CameraSettings.KEY_SELFIE_MIRROR); if (selfieMirrorPref != null && selfieMirrorPref.getValue() != null && selfieMirrorPref.getValue().equalsIgnoreCase("enable")) { - jpegData = flipJpeg(jpegData); - exif = Exif.getExif(jpegData); - exif.addOrientationTag(orientation); + jpegData = flipJpeg(jpegData, info.orientation); + jpegData = addExifTags(jpegData, orientation); } } if (!mIsImageCaptureIntent) { |