FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Image rotation from camera · Issue #1559 · NativeScript/NativeScript · GitHub

Image rotation from camera #1559

Description

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);
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


    Back | FazBrowse Home | New Git URL