我写了一个自定义相机活动来处理我在调用意图图像捕获时遇到的某些问题.用户可以选择保存图像,也可以只使用从中返回的数据OnPictureTakenCallback.
我遇到的问题是正确显示图像的方向.我强制通过调用以纵向显示活动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 …Run Code Online (Sandbox Code Playgroud)