I am using exifInterface for the code with the question about image rotation below: Facing the problem of capturing images from the camera.
Bitmap b = BitmapFactory.decodeFile(imagePath);
- Resize a raster image by scaling it to the appropriate level
int width = b.getWidth();
int height = b.getHeight();
int newWidth = 150;
int newHeight = 150;
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
- Image Orientation Control
ExifInterface exif = new ExifInterface(imagePath);
String orientation = exif.getAttribute(ExifInterface.TAG_ORIENTATION);
if (orientation.equals(ExifInterface.ORIENTATION_NORMAL)) {
} else if (orientation.equals(ExifInterface.ORIENTATION_ROTATE_90+"")) {
matrix.postRotate(90);
} else if (orientation.equals(ExifInterface.ORIENTATION_ROTATE_180+"")) {
matrix.postRotate(180);
} else if (orientation.equals(ExifInterface.ORIENTATION_ROTATE_270+"")) {
matrix.postRotate(270);
}
out = new FileOutputStream(new File("some output file path"));
Bitmap resizedBitmap = Bitmap.createBitmap(b, 0, 0, width, height, matrix, true);
resizedBitmap.compress(Bitmap.CompressFormat.JPEG, 70, out);
This code does not work to solve the rotation problem, please give me a guide. On Lg devices, this exifinterface always returns 0 orientations, Samsung devices return 6 and 1.
How to fix this problem with all devices like HTC, Motorola, Samsung, Sony and LG.
I thank you all, please help me.
source
share