Rotate Image Taken From Camera Or Gallery
I am capturing image from camera and selecting image from gallery. In samsung devices the images gets rotate after captured. I want to rotate image to straight if they are rotated.
Solution 1:
Replace
int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);
With
int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
And tell if it works
Solution 2:
I also faced the same issue once in my project and got it going by below code :
//imageFileUri is fileUri.getPath() that is being passedprivate Bitmap getImageBitmap(String imageFileUri) {
BitmapFactory.Optionsopts=newBitmapFactory.Options();
opts.inSampleSize = 3;
Bitmapbm= BitmapFactory.decodeFile(imageFileUri, opts);
ExifInterface exif;
StringorientString=null;
try {
exif = newExifInterface(imageFileUri);
orientString = exif.getAttribute(ExifInterface.TAG_ORIENTATION);
} catch (IOException e) {
if (BuildConfig.DEBUG) {
e.printStackTrace();
}
}
intorientation= (orientString != null) ? Integer.parseInt(orientString)
: ExifInterface.ORIENTATION_NORMAL;
introtationAngle=0;
if (orientation == ExifInterface.ORIENTATION_ROTATE_90)
rotationAngle = 90;
if (orientation == ExifInterface.ORIENTATION_ROTATE_180)
rotationAngle = 180;
if (orientation == ExifInterface.ORIENTATION_ROTATE_270)
rotationAngle = 270;
intw= bm.getWidth();
inth= bm.getHeight();
Matrixmtx=newMatrix();
mtx.postRotate(rotationAngle);
return Bitmap.createBitmap(bm, 0, 0, w, h, mtx, true);
}
Post a Comment for "Rotate Image Taken From Camera Or Gallery"