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.
And also refer this link https://stackoverflow.com/a/6124375/1441666
the selected answer just gives the the possible rotation that may have been saved in EXIF header. in several cases camera doesn't set "ExifInterface.TAG_ORIENTATION" attribute in EXIFHeader so it will be 0(ExifInterface.ORIENTATION_UNDEFINED). and event if it is set it will be true in only one case/orientation when the picture is taken. you have to manually set rotation in camera parameters using setRotation() method. the documentation of setRotation() is very clear and also explains how to calculate rotation with consideration of device rotation and camera sensor orientation(usually landscape).
so check out setRotation() method . thats what you need to change.
I'm using the following code for this:
getUriPath:
You can use this to get orientation from a
Uri
And as note rotation '3 = 180, 6 = 90, 8 = 270'
try this code snippet
and then rotate the matrix as per orientation you get