camera.setParameters failed in android

前端 未结 1 1236
走了就别回头了
走了就别回头了 2020-11-29 00:58

I have included the camera functionality in my application. I have also launched the app in the market. I got an error message from one of the users that he is getting an er

相关标签:
1条回答
  • 2020-11-29 01:29

    It is failing because not all devices support arbitrary preview sizes. Apparently some do but you can't rely on it. In your surfaceChanged method you need to do something like this:

    public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
        Camera.Parameters parameters = camera.getParameters();
        List<Camera.Size> previewSizes = parameters.getSupportedPreviewSizes();
    
        // You need to choose the most appropriate previewSize for your app
        Camera.Size previewSize = // .... select one of previewSizes here
    
        parameters.setPreviewSize(previewSize.width, previewSize.height);
        camera.setParameters(parameters);
        camera.startPreview();
    }
    

    You'll have to figure out a way to scale this so that you don't lose the aspect ratio etc.

    For reference here is the Android SDK doc.

    0 讨论(0)
提交回复
热议问题