Android将照片旋转90度(由相机拍摄)
问题描述:
我正在使用我的Samsung Galaxy SII设备拍摄照片。 保存并在屏幕上显示后,我看到它旋转了90度。Android将照片旋转90度(由相机拍摄)
我知道这是一些设备问题 - 它不会发生在所有设备上。
我正在拍摄照片,使用给定的照相机意图并将其保存在onActivityResult函数中。
我环顾四周,但没有找到一个坚实的解决方案。
任何想法如何找到问题,并将其仅旋转回“有问题的”设备?
答
这是一个基于不同制造商设置的错误。有些手机旋转它们,有些则不旋转。看到该链接,这是问题#1193
答
我想这可能是您的方向传感器的问题..您是否在您的程序中处理传感器值..要知道用户何时拍摄照片时设备处于水平或垂直方向..
+2
不能依靠它 - 因为它工作在某些设备上良好,而不是其他 – user1136875 2012-01-14 20:43:06
答
通道中,从相机捕获的文件路径
public Bitmap rotateBitmapOrientation(String photoFilePath) {
// Create and configure BitmapFactory
BitmapFactory.Options bounds = new BitmapFactory.Options();
bounds.inJustDecodeBounds = true;
BitmapFactory.decodeFile(file, bounds);
BitmapFactory.Options opts = new BitmapFactory.Options();
Bitmap bm = BitmapFactory.decodeFile(file, opts);
// Read EXIF Data
ExifInterface exif = new ExifInterface(file);
String orientString = exif.getAttribute(ExifInterface.TAG_ORIENTATION);
int orientation = orientString != null ? Integer.parseInt(orientString) : ExifInterface.ORIENTATION_NORMAL;
int rotationAngle = 0;
if (orientation == ExifInterface.ORIENTATION_ROTATE_90) rotationAngle = 90;
if (orientation == ExifInterface.ORIENTATION_ROTATE_180) rotationAngle = 180;
if (orientation == ExifInterface.ORIENTATION_ROTATE_270) rotationAngle = 270;
// Rotate Bitmap
Matrix matrix = new Matrix();
matrix.setRotate(rotationAngle, (float) bm.getWidth()/2, (float) bm.getHeight()/2);
Bitmap rotatedBitmap = Bitmap.createBitmap(bm, 0, 0, bounds.outWidth, bounds.outHeight, matrix, true);
// Return result
return rotatedBitmap;
}
因此,据我所见 - 我必须从相机请求横向模式?有没有办法找出某种程度上应用程序运行的设备是否在处理它?或者我应该让所有设备都使用横向模式并遮挡肖像(这不是一个很好的解决方案) – user1136875 2012-01-15 07:27:49
我自己还没弄清楚那一部分。我个人会尝试http://developer.android.com/guide/topics/media/camera.html#custom-camera,看看是否有所作为。 – 2012-01-15 07:32:25
如果你想知道 - 请让我知道:) – user1136875 2012-01-15 14:06:12