【发布时间】:2016-05-08 18:49:08
【问题描述】:
我正在构建一个使用相机功能的 android 应用程序。我遇到的问题是我从前置摄像头获得的图像数据(字节 [])在我的三星 s7 和 nexus 手机上颠倒过来。它在预览中看起来是正确的,但是在我按原样保存数据然后在画廊中显示图像之后,它们都是颠倒的。我知道我可以在保存之前翻转图像数据,但我已经在运行 4.4 (kitkat) 的蓝光 C 5.0 HD 上测试了代码,并且该手机上的图像数据以正确的方式出现。所以总是翻转图像会导致其他设备上的错误。有人告诉我这个问题是因为在制造新的三星和 nexus 手机时,前置摄像头是倒置的以节省空间。我不确定这是否正确,但如果是这样,如果我翻转所有图像,它将弄乱具有正确相机方向的手机。那么有没有办法在保存图片之前检测图片数据的方向呢?
这是我正在使用的代码:
mCamera.takePicture(null, null, mPicture);
回调:
private final Camera.PictureCallback mPictureCallback = new Camera.PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
processCameraCallback(data);
}
};
处理数据:
public void processCameraCallback(byte[] data) {
confirmPhoto(true);
//Make a new empty picture file
try {
pictureFile = Utils.createImageFile();
} catch (IOException ex) {
// Error occurred while creating the File
Log.e(TAG, "Failed to create photo file: " + ex.toString());
confirmPhoto(false);
return;
}
//Write the file to the storage
try {
FileOutputStream fos;
if (pictureFile != null) {
fos = new FileOutputStream(pictureFile);
fos.write(data);
fos.close();
}
} catch (FileNotFoundException e) {
Log.d(TAG, "File not found: " + e.getMessage());
confirmPhoto(false);
return;
} catch (IOException e) {
Log.d(TAG, "Error accessing file: " + e.getMessage());
confirmPhoto(false);
return;
}
}
【问题讨论】:
-
你有没有想过这个问题?我在使用本机相机应用程序的 S7 上遇到了同样的问题,还补偿了 EXIF 数据中返回的方向。
标签: android camera android-camera orientation