Skip to content

Image rotation from camera #1559

Description

@dkallkro

ANDROID ONLY:
Image retuned from camera module is rotated wrong on a lot of android devices.
to fix this add this code in the camera.android.js file:

Add just before this line : resolve(imageSource.fromNativeSource(scaledSizeImage));

var ei = new android.media.ExifInterface(tempPicturePath);
var orientation = ei.getAttributeInt(android.media.ExifInterface.TAG_ORIENTATION, android.media.ExifInterface.ORIENTATION_NORMAL);

                    switch(orientation) {
                    case android.media.ExifInterface.ORIENTATION_ROTATE_90:
                        scaledSizeImage = rotateBitmap(scaledSizeImage, 90);
                        break;
                    case android.media.ExifInterface.ORIENTATION_ROTATE_180:
                        scaledSizeImage = rotateBitmap(scaledSizeImage, 180);
                        break;
                    case android.media.ExifInterface.ORIENTATION_ROTATE_270:
                        scaledSizeImage = rotateBitmap(scaledSizeImage, 270);
                        break;
                    }

And then add this at the end of file:

var rotateBitmap = function (source, angle)
{
var matrix = new android.graphics.Matrix();
matrix.postRotate(angle);
return android.graphics.Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true);
}

Metadata

Metadata

Assignees

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions