检测使用的摄像头(前置或后置摄像头) [英] Detect camera used (front-facing or rear-facing camera)

查看:334
本文介绍了检测使用的摄像头(前置或后置摄像头)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检测用户用来捕获图像的摄像机,然后根据类型(前/后摄像机)初始化一个值.

I want to detect which camera that my user used to capture an image, to then initialize a value according to the type (Front/Rear camera).

以下是我的尝试,运行应用程序后,值始终为0.417!

The following is my trying, After I run the app, value is always 0.417 !

public class Home extends Activity {
double value = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.MainActivity);
    AlertDialog.Builder builder = new AlertDialog.Builder(this);

    input = new EditText(this);
    builder.setView(input);

    builder.setPositiveButton("Next", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int witch) {
            Intent camera_intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            File file = getFile();
            camera_intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
            startActivityForResult(camera_intent, CAM_REQUEST);
        }
    });

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == CAM_REQUEST && resultCode == RESULT_OK) {
            Intent intent = new Intent(this, Enrollment.class);
            Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
            if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
                this.value = 0.417;
            }
            else if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK){
                this.value = 0.5;
            }
            startActivity(intent);                
    }
}

顺便说一句,捕获图像效果完美,我只需要确定相机的类型(前置或后置)即可.

BTW, capture image work perfectly, I just need to determine the type of camera (front or rear).

推荐答案

您无法知道图像是来自前置摄像头,后置摄像头还是其他任何东西(IP摄像机,假冒产品)图片等).您正在将图像捕获委托给第三方应用程序.第三方应用程序的操作取决于该应用程序的开发人员和用户.

You have no way of knowing whether the image came from a front-facing camera, a rear-facing camera, or anything else (an IP camera, a fake picture, etc.). You are delegating the image capture to a third-party app. What that third party app does is up to that app's developers and the user.

这篇关于检测使用的摄像头(前置或后置摄像头)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆