24

我有一个在某些设备上可以正常工作的定制相机。它在三星 Galaxy Gran Duos (samsung-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);
        }
    }
}

日志猫:

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

4 回答 4

1

我认为您需要确认您的相机支持变焦,camera.isZoomSupported()然后如果支持,您需要取消自动对焦camera.cancelAutoFocus()以防止图像失真。但这仅在您的设备实际支持缩放时才有效。如果不是,您需要捕获保留图像并使用Bitmap.createBitmap所需的部分进行放大。

于 2015-09-13T16:08:36.440 回答
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
}
于 2015-04-15T12:51:18.197 回答
0

拍照后是否再次启动相机预览?

添加这个 camera.startPreview();

尝试这个

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

    public void onPictureTaken(byte[] data, Camera camera) {
           camera.startPreview();
        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());
        } 
    }
};
于 2015-04-22T07:28:29.150 回答
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;
}
于 2016-08-15T10:43:16.903 回答