Camera crashes in Android 2.2

后端 未结 3 1238
感动是毒
感动是毒 2020-12-21 12:10

I have tested my application on the Android SDK on everything from 1.5 to 2.2 and the camera code in my activity works fine. Running it on a device with 2.1 is also working.

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-21 12:50

    The problem is that the width and height passed by the surfaceChanged method is not a preview size supported.

    So if you wanna set the preview size (parameters.setPreviewSize), you need to set a supported preview size. The method getPreviewSize() returns an available preview size. So your surfaceChanged method can be like that:

    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
        Camera.Parameters parameters = camera.getParameters();
    
        Size pSize = camera.getParameters().getPreviewSize();
        Log.d(TAG, "Setting preview size: " + pSize.width + " x " + pSize.height);
    
        parameters.setPreviewSize(pSize.width, pSize.height);
        camera.setParameters(parameters);
        camera.startPreview();
    }
    

    You can also get a list of the supported preview sizes using the method getSupportedPreviewSizes() available from android api version 5.

提交回复
热议问题