我写了一个自定义相机活动来处理一些问题,我一直在使用某些安卓设备时调用意图图像捕获。用户可以选择保存图像,也可以使用从OnPictureTakenCallback
返回的数据。Android定位问题与自定义相机活动
我遇到的问题是正确显示图像的方向。我通过致电SetRequestedOrientation
强制活动以纵向显示。
如何知道用户拍摄照片时相机的正确方向? 即,用户可以以90(人像)的旋转拍摄照片。
我试图在窗口管理器的默认显示屏上使用getRotation()
,但是将请求的方向设置为纵向,只返回Surface.ROTATION_0
。
更新: 为了澄清我的其他问题,我怎么能确定从刚刚byte[]
数据,如果用户不保存图像画面回调的方向是什么?
更新:使用此代码尝试下面的答案后,我得到的是ExifInterface.ORIENTATION_NORMAL。我也改变了我的代码,以保存从相机返回的文件,因为我不确定是否有简单的方法来确定只有byte[]
数据的方向。
private PictureCallback mPicture = new PictureCallback()
{
@Override
public void onPictureTaken(byte[] data, Camera camera)
{
File directory = new File(android.os.Environment.getExternalStoragePublicDirectory(android.os.Environment.DIRECTORY_PICTURES),
"MyApp");
if(!directory.exists())
{
if(!directory.mkdirs())
{
Log.d("CAMERA", "Unable to create directory to save photos.");
return;
}
}
File file = new File(directory.getPath() + file.separator + "IMG_" + SimpleDateFormat.getDateTimeInstance().toString() + ".jpg");
FileOutputStream fos = new FileOutputStream(file);
fos.write(data);
fos.close();
ExifInterface exif = new ExifInterface(file.getCanonicalPath());
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
int rotate = 0;
switch (orientation)
{
case ExifInterface.ORIENTATION_ROTATE_90:
rotate = 90;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
rotate = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_270:
rotate = 270;
break;
case default:
break;
}
}
};
任何一个可以帮助http://stackoverflow.com/questions/28379130/how设置相机图像方向 – 2015-02-07 13:28:37