Android Galaxy S4相机bug

时间:2013-08-24 13:33:35

标签: android camera

自定义相机应用和三星Galaxy S4手机存在问题。有时,当应用程序拍照时,S4手机可以同时拍摄多张照片。它偶尔会发生在为其他设备工作的相同代码中。以下是拍照的代码:

Parameters params = camera.getParameters();
params.setRotation(rotation);
camera.setParameters(params);
camera.autoFocus(new Camera.AutoFocusCallback() {

    @Override
    public void onAutoFocus(boolean success, Camera camera) {
        camera.takePicture(shutterCallback, null, PreviewCallback.this);
    }
});

@Override
public void onPictureTaken(byte[] data, Camera camera) {
    pictureCallback.onPictureTaken(previewData, data);
    camera.startPreview();
    Parameters params = camera.getParameters();
    params.setRotation(rotationOrig);
    camera.setParameters(params);
}

旋转仅用于正确的exif旋转标记。

1 个答案:

答案 0 :(得分:3)

contract for Camera.AutoFocusCallback.onAutoFocus并不认为在调用camera.autoFocus()后它只会被触发一次。所以,我只想添加一个布尔变量,例如

camera.autoFocus(new Camera.AutoFocusCallback() {

    boolean once = true;
    @Override
    public void onAutoFocus(boolean success, Camera camera) {
    if (once && success) {
        camera.takePicture(shutterCallback, null, PreviewCallback.this);
        once = false;
        }
    }
});

顺便说一句,你应该检查第一个参数值 - 如果自动对焦失败,你可能不想在第一时间拍摄照片。