【发布时间】:2015-06-19 11:54:16
【问题描述】:
我有一个 Android 应用程序,允许用户使用他们的相机上传个人资料照片。问题是,当用户使用前置摄像头拍照时,手机上存储的图像会被镜像。
我可以将图像镜像回其原始状态,但是我无法专门对前置摄像头图片执行翻转。
有没有办法判断这张照片是不是用前置摄像头拍摄的?
这是我用来获取图片的一些代码
final boolean isCamera;
if (data == null) {
isCamera = true;
} else {
final String action = data.getAction();
if (action == null) {
isCamera = false;
} else {
isCamera = action.equals(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
}
}
Uri selectedImageUri;
if (isCamera) {
selectedImageUri = outputFileUri;
} else {
selectedImageUri = (data == null) ? null : data.getData();
}
Bitmap selectedBitmap;
// Check if the url is not null
if (selectedImageUri != null) {
// store the new bitmap
selectedBitmap = BitmapFactory.decodeFile(outputFileUri.getEncodedPath());
int i = ExifInterface.ORIENTATION_FLIP_HORIZONTAL;
// if camera and front facing flip
// HERE IS WHERE I NEED HELP
if(isCamera && selectedBitmap != null){
selectedBitmap = UtilsLibrary.flip(selectedBitmap);
FileOutputStream out = null;
try {
out = new FileOutputStream(selectedImageUri.getEncodedPath());
selectedBitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (out != null) {
out.flush();
out.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
cropImage(selectedImageUri);
任何帮助将不胜感激,谢谢。
【问题讨论】:
标签: android bitmap camera mediastore image-capture