Android自定义相机变焦后冻结

时间:2015-04-08 13:57:46

标签: android camera freeze samsung-galaxy-camera

我有一个可在某些设备上正常工作的自定义相机。它适用于三星Galaxy Gran Duos(三星-gt i9082,Android 4.2.2)但是当我尝试捕捉图像时,我之前放大了,它冻结了,没有崩溃,唯一的出路就是按下返回键。这只发生在三星Galaxy Gran Duos上。

我用来拍照的代码:

    Camera.PictureCallback photoCallback = new Camera.PictureCallback() {

    public void onPictureTaken(byte[] data, Camera camera) {

        try {

        } catch (Exception e) {
            if (flePicture== null){
                Log.d("camera", "Error creating media file, check storage permissions: " +
                        e.getMessage());
                return;
            }
        }

        try {
            FileOutputStream fos = new FileOutputStream(flePicture);
            fos.write(data);
            fos.close();
        } catch (FileNotFoundException e) {
            Log.d("camera", "File not found: " + e.getMessage());
        } catch (IOException e) {
            Log.d("camera", "Error accessing file: " + e.getMessage());
        } 
    }
};

用于放大的代码:

private void zoomIn() {
    if (pblnInPreview) {
        Camera.Parameters parameters = camCamera.getParameters();

        if ((parameters.getZoom() + 1) < parameters.getMaxZoom()) {
            parameters.setZoom(parameters.getZoom() + 1);
            camCamera.setParameters(parameters);
        }
    }
}

logcat的:

04-07 17:21:14.386: E/BrcmCamera(130): processControlBuffer: Corrupt stream error raised by camera - sensor communication failure

2 个答案:

答案 0 :(得分:0)

这不是一个非常相关的答案。我知道。

但我想说三星4.2.2有许多缺陷问题。 它有ClipboardManager崩溃,ActionBar AppCompat崩溃等等。

只需使用简单的if子句对其进行过滤,即可挽救生命。

if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN_MR1 && Build.MANUFACTURER.toUpperCase().contains("SAMSUNG")){
    // ignore
}else{
    // your logic on the go
}

答案 1 :(得分:0)

特定类型的内核存在一些问题。

尝试这种方法。

private static final String TAG = Test.class.getSimpleName();

private boolean isPreviewStarted;
private Camera camera;

Camera.PictureCallback photoCallback = new Camera.PictureCallback() {
    public void onPictureTaken(byte[] data, Camera camera) {

        // check if this needs to stop the preview
        if (deviceNeedsStopPreviewToShoot()) {
            stopPreview();
        }

        // save your image

        // restart preview if needed.
        startPreview();

    }
};

public void startPreview() {
    if (!isPreviewStarted && camera != null) {
        camera.startPreview();
        isPreviewStarted = true;
    }
}

public void stopPreview() {
    if (isPreviewStarted && camera != null) {
        camera.stopPreview();
        isPreviewStarted = false;
    }
}

public static boolean deviceNeedsStopPreviewToShoot() {
    String[] oldDevices = {"smdk4210", "aries"};
    boolean needs = Arrays.asList(oldDevices).contains(Build.BOARD);
    Log.e(TAG, "Device " + Build.BOARD + (needs ? " needs " : " doesn't need ") + "to stop preview");
    return needs;
}