我有一个纵向模式的相机应用程序,它从前端和后端相机拍摄照片。问题就像捕获的图像以错误的方式旋转......
对于预览,我使用了以下代码....
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);
但是捕获的图像以错误的方式旋转。我也尝试使用旋转捕获的图像matrix.postRotate(bitmap)
。这在像nexus这样的某些设备中也不起作用。我也尝试了EXIF。但是这里我有url而不是filepath。那也不行。谁能帮我 ?