检测是否图像是用前置摄像头 [英] Detect if image was taken with front camera
问题描述
我有一个Android应用程序,允许用户使用他们的相机上传个人资料图片。问题是,当用户需要使用前置摄像头的照片,存储在手机上的图像镜像。
I have an Android app that allows a user to upload a profile picture using their camera. The problem is, when the user takes a photo with the front facing camera, the image stored on the phone is mirrored.
我能够将图像镜像回到它的原始状态然而,我无法对前方进行翻转专门面对镜头的照片。
I am able to mirror the image back to it's original state however, I am unable to perform the flip on front facing camera pictures exclusively.
有没有办法找出如果照片拍摄的前置摄像头?
Is there a way to figure out if the picture was taken with the front facing camera?
下面是一些code我用获取的图片
Here is some code I use for getting the picture
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);
任何帮助将大大AP preciated,谢谢你。
Any help would be greatly appreciated, thank you.
推荐答案
请尝试以下code:
CameraInfo cameraInfo = new CameraInfo();
if (cameraInfo.facing == CameraInfo.CAMERA_FACING_FRONT) {
// do your logic
}
这篇关于检测是否图像是用前置摄像头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!