You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by GitBox <gi...@apache.org> on 2018/08/29 18:27:56 UTC

[GitHub] ffMathy commented on a change in pull request #100: CB-13683: (android) cordova-plugin-media-capture rotates pictures with some devices

ffMathy commented on a change in pull request #100: CB-13683: (android) cordova-plugin-media-capture rotates pictures with some devices
URL: https://github.com/apache/cordova-plugin-media-capture/pull/100#discussion_r213786721
 
 

 ##########
 File path: src/android/Capture.java
 ##########
 @@ -537,6 +554,51 @@ private Uri whichContentStore() {
         }
     }
 
+    @Nullable
+    private Bitmap rotateAccordingToExifOrientation(Uri uri) {
+        Context context = this.cordova.getContext();
+        int orientation;
+        Bitmap bitmap;
+        try {
+            InputStream inputStream = context.getContentResolver().openInputStream(uri);
+            if (inputStream == null)
+                throw new IOException("input stream from ContentResolver is null");
+            ExifInterface ei = new ExifInterface(inputStream);
+            orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);
+            bitmap = MediaStore.Images.Media.getBitmap(context.getContentResolver(), uri);
+        } catch (IOException e) {
+            LOG.e(LOG_TAG, "Failed reading bitmap", e);
+            return null;
+        }
+
+        Bitmap rotatedBitmap;
+        switch (orientation) {
+            case ExifInterface.ORIENTATION_ROTATE_90:
+                rotatedBitmap = rotateImage(bitmap, 90);
+                break;
+
+            case ExifInterface.ORIENTATION_ROTATE_180:
+                rotatedBitmap = rotateImage(bitmap, 180);
+                break;
+
+            case ExifInterface.ORIENTATION_ROTATE_270:
+                rotatedBitmap = rotateImage(bitmap, 270);
+                break;
+
+            case ExifInterface.ORIENTATION_NORMAL:
+            default:
+                rotatedBitmap = bitmap;
+        }
+        return rotatedBitmap;
+    }
+
+    private Uri fromBitmapToUri(Context context, Bitmap inImage) {
+        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
+        inImage.compress(Bitmap.CompressFormat.JPEG, 85, bytes);
 
 Review comment:
   Why can't we just set it to `100`?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org