[英]Detect if image was taken with front camera
我有一个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);
非常感谢任何帮助,谢谢。
请尝试以下代码:
CameraInfo cameraInfo = new CameraInfo();
if (cameraInfo.facing == CameraInfo.CAMERA_FACING_FRONT) {
// do your logic
}
我看到你的代码中有这一行。 这就是你需要的。 你只需要完成它。
int i = ExifInterface.ORIENTATION_FLIP_HORIZONTAL;
通常,您需要检测从文件中读取的所有图片的方向。
请使用以下方法。
ExifInterface exif = new ExifInterface(outputFileUri.getEncodedPath());
String orientation = exif.getAttribute(ExifInterface.TAG_ORIENTATION);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.