I have a camera app in portrait mode which takes pictures from both front and back end cameras.The issue is like the captured images are rotated in a wrong way...
For preview i have used the following code....
Camera.Parameters parameters = camera.getParameters();
android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo();
android.hardware.Camera.getCameraInfo(defaultCameraId, info);
int rotation = this.getWindowManager().getDefaultDisplay()
.getRotation();
if (Integer.parseInt(Build.VERSION.SDK) >= 8) {
int degrees = 0;
switch (rotation) {
case Surface.ROTATION_0:
degrees = 0;
break;
case Surface.ROTATION_90:
degrees = 90;
break;
case Surface.ROTATION_180:
degrees = 180;
break;
case Surface.ROTATION_270:
degrees = 270;
break;
}
int result;
if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
result = (info.orientation + degrees) % 360;
result = (360 - result) % 360; // compensate the mirror
} else { // back-facing
result = (info.orientation - degrees + 360) % 360;
}
camera.setDisplayOrientation(result);
} else {
parameters.set("orientation", "portrait");
}
camera.setParameters(parameters);
But the captured images are rotated in a wrong way.i have also tried to rotate the captured image using matrix.postRotate(bitmap)
.That too doesn't work in some devices like nexus..I tried EXIF also.But here i have url instead of filepath.That doesn't work as well. can anyone help me ?
You can refer below code.
ExifInterface exif = new ExifInterface(SourceFileName); //Since API Level 5
String exifOrientation = exif.getAttribute(ExifInterface.TAG_ORIENTATION);
And also refer this link https://stackoverflow.com/a/6124375/1441666
You can use this to get orientation from a Uri
String filePath = mImageUri.getPath();
if (filePath != null) {
rotation = -1;
ExifInterface exif = new ExifInterface(filePath); // Since
// API
// Level
// 5
rotation = Integer.parseInt(exif.getAttribute(ExifInterface.TAG_ORIENTATION));
// //Log.v("roation",
// exif.getAttribute(ExifInterface.TAG_ORIENTATION));
}
}
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "Internal error", Toast.LENGTH_LONG).show();
Log.e(e.getClass().getName(), e.getMessage(), e);
}
And as note rotation '3 = 180, 6 = 90, 8 = 270'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With