【发布时间】:2015-05-12 12:13:07
【问题描述】:
使用相机 API 和预览SurfaceView 在设备处于纵向时拍摄照片后,创建的图像将旋转 90 度。我知道这是一个影响 一些 android 手机的问题,包括我正在开发的三星 Galaxy S5 - 有几个堆栈溢出问题 - see here 和 here。建议图像文件将包含 EXIF 元数据,该元数据将说明旋转的方向,以便您可以使用它来旋转图像以获得正确的方向。我已经这样做了,但由于某种原因,ExifInterface.TAG_ORIENTATION 是1 - ORIENTATION_NORMAL。因此,我无法确定图像需要旋转多少才能确保它适用于所有设备。尽管该解决方案似乎对其他人有效。我做错了什么,或者如何解决这个问题?
一些伪代码:
//in onCreate
camera = getCameraInstance();
setCameraDisplayOrientation(this, cameraID, camera);
//in OnClickListener
camera.takePicture(null, null, picCallback);
//callback:
onPictureTaken {
//create a File using getExternalStoragePublicDirectory(PICTURES) + "appname" - create directory if doesn't exist
//write file to disk via FileOutputStream
//attempt to correct the image orientation if needed
Bitmap correctBitmap = getCorrectOrientationBitmap(picFile.getAbsolutePath());
}
public Bitmap getCorrectOrientationBitmap(String photoFilePath) {
// Read EXIF Data
ExifInterface exif = null;
try {
exif = new ExifInterface(photoFilePath);
} catch (IOException e) {
e.printStackTrace();
return null;
}
String orientation = exif.getAttribute(ExifInterface.TAG_ORIENTATION);
//problem: orientation is 1 - ORIENTATION_NORMAL despite the fact the image is rotated to the right 90 degrees
//rotate the image based on EXIF orientation
}
//later on
myImageView.setImageBitmap(correctBitmap);
//shows image rotated to the right because getCorrectOrientationBitmap didn't rotate it
【问题讨论】:
-
stackoverflow.com/questions/14066038/… 仔细阅读所有答案..你没有得到正确的 bmp.ORIENT ..请参阅链接上“mediaStore”上的内容查询..这是三星唯一的问题 AFAIK
-
@RobertRowntree 我没有使用
MediaStore -
@JordanH 你能解决这个问题吗?我也被困在同一点上。图像被保存为旋转。您可以为此发布解决方案吗?
标签: android bitmap imageview android-camera exif