我在肖像模式下有一个相机应用程序,可以从前端和后端拍摄照片,cameras.The问题就像捕获的图像被以错误的方式旋转…
为了预览,我使用了以下代码...
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)
.That来旋转捕获的图像。在一些设备上,如nexus..我尝试了also.But,在这里我有url,而不是filepath.That,也不能工作。有人能帮我吗?
发布于 2012-10-25 20:29:52
你可以参考下面的代码。
ExifInterface exif = new ExifInterface(SourceFileName); //Since API Level 5
String exifOrientation = exif.getAttribute(ExifInterface.TAG_ORIENTATION);
发布于 2012-11-05 00:34:12
您可以使用它从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);
}
如音符旋转'3 = 180,6= 90,8= 270‘
发布于 2012-11-04 01:49:49
为此,我使用了以下代码:
ExifInterface exif = new ExifInterface(getUriPath(uri));
int orientation = exif.getAttributeInt(
ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL);
getUriPath:
public String getUriPath(Uri uri) {
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(uri, projection, null, null,
null);
if (cursor != null) {
int column_index = cursor.getColumnIndexOrThrow(projection[0]);
cursor.moveToFirst();
String filePath = cursor.getString(column_index);
cursor.close();
return filePath;
} else
return null;
}
https://stackoverflow.com/questions/13062769
复制相似问题