我怎么能前后置摄像头之间切换? [英] How can I toggle between front and rear facing cameras?

查看:173
本文介绍了我怎么能前后置摄像头之间切换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在我的应用程序前,后置摄像头之间切换。我的问题是,我可以打开前置摄像头,或者我可以打开后置摄像头。但什么是显示在preVIEW当相机已经打开我不能切换。作为一个概念证明,我只是想把我已经打开了后置摄像头preVIEW切换到朝前。
我试图写一个方法toggleCamera看起来是这样的:

I need to toggle between front and rear facing cameras in my app. My problem is, I can open the front-facing camera, or I can open the rear-facing camera. But I can't switch what is shown in the preview once the camera is already open. As a proof of concept, I'm just trying to get my already opened rear-facing camera preview to switch to front-facing. I'm trying to write a method toggleCamera that looks something like this:

public void toggleCamera(){
    mCamera.stopPreview();
    int frontCameraId = 0;
    for (int camNo = 0; camNo < Camera.getNumberOfCameras(); camNo++) {
    CameraInfo camInfo = new CameraInfo();
        Camera.getCameraInfo(camNo, camInfo);
        if (camInfo.facing==(Camera.CameraInfo.CAMERA_FACING_FRONT)) {
            frontCameraId = camNo;
        }
    }
    mCamera.release();
    mCamera = Camera.open(frontCameraId);
    mCamera.startPreview();
    Log.d(TAG + "Restarting camera", ""+frontCameraId);
}

现在,相机只是冻结当这种情况发生。我已经看到了,我应该设置cameraParameter摄像机ID但是这并没有为我工作了几个地方,我发现没有文件支持这个。

Right now, the camera just freezes when this happens. I've seen in a few places that I should set the cameraParameter "camera-id" but this hasn't worked for me, and I found no documentation supporting this.

推荐答案

我只是用的打开飞回/前置摄像头希望它会帮助你。

i just implement this with the help of switch back/front camera on fly hope it will help you as well.

这篇关于我怎么能前后置摄像头之间切换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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