Skip to content Skip to sidebar Skip to footer

Capturing Image From Camera, Results In Blowing Up The Orientation

I am trying to capture image from the camera, it works fine with landscape mode, when I take the picture in portrait it is rotated. Below is the code I am using: Bitmap

Solution 1:

you can arrange your code as follow...

Bitmapbm= BitmapFactory.decodeFile(largeImagePath, opts);
    ExifInterface ei;
    try {
        ei = newExifInterface(largeImagePath);
        intorientation= ei.getAttributeInt(ExifInterface.TAG_ORIENTATION,
                ExifInterface.ORIENTATION_NORMAL);
        switch (orientation) {
        case ExifInterface.ORIENTATION_ROTATE_90:
            bitmap = rotateImage(bitmap, 90);
            break;
        case ExifInterface.ORIENTATION_ROTATE_180:
            bitmap = rotateImage(bitmap, 180);
            break;
        case ExifInterface.ORIENTATION_ROTATE_270:
            bitmap = rotateImage(bitmap, 270);
            break;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

write rotateImage() method as follows....

private Bitmap rotateImage(Bitmap source, float angle) {

    Bitmapbitmap=null;
    Matrixmatrix=newMatrix();
    matrix.postRotate(angle);
    try {
        bitmap = Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(),
                matrix, true);
    } catch (OutOfMemoryError err) {
        err.printStackTrace();
    }
    return bitmap;
}

Solution 2:

Use bm.getWidth() and bm.getHeight() instead bounds.outWidth and bounds.outHeight in createBitmap() method.

Post a Comment for "Capturing Image From Camera, Results In Blowing Up The Orientation"