且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Android相机对焦模式

更新时间:2023-12-02 10:08:52

尝试一下:

public void takePhoto(File photoFile, String workerName, int width, int height, int    quality) {
if (getAutoFocusStatus()){
    camera.autoFocus(new AutoFocusCallback() {
        @Override
        public void onAutoFocus(boolean success, Camera camera) {
            camera.takePicture(shutterCallback, rawCallback, jpegCallback);
        }
    }); 
}else{
    camera.takePicture(shutterCallback, rawCallback, jpegCallback);
}

但是,我也看到了这个方法的工作,可能更准确:

However, I've also seen this to work, possibly more accurately:

if (getAutoFocusStatus()){
    camera.autoFocus(new AutoFocusCallback() {
        @Override
        public void onAutoFocus(boolean success, Camera camera) {
           if(success) camera.takePicture(shutterCallback, rawCallback, jpegCallback);
        }
    }); 
}else{
    camera.takePicture(shutterCallback, rawCallback, jpegCallback);
}

最后一个在成功完成聚焦时拍摄照片.与QR扫描代码一起使用时效果很好.我相信同样的情况也适用于这样的情况.

The last one takes the picture at the moment the focussing is successfully completed. It works very well for using with QR scanning codes. I believe the same applies to cases like this.