开发者

Java.lang.RuntimeException:setParameters failed at android.hardware.camera.native_setParameter(Native Method) [duplicate]

开发者 https://www.devze.com 2022-12-26 00:59 出处:网络
This question already has an answer here: 开发者_运维知识库 camera.setParameters failed in android
This question already has an answer here: 开发者_运维知识库 camera.setParameters failed in android (1 answer) Closed 4 years ago.

I'm using the Android APIDemo sample code. but my phone is G2 Android OS 2.1


before you set caemra Parameters , you can use camera.getParameters().flatten() to log all the parameters that camera support. so you can use the right parameter.


replace surfaceCreated methood to this , and tell me if it work

 public void surfaceCreated(SurfaceHolder holder){
        // The Surface has been created, now tell the camera where to draw the
        // preview.


        Log.d(TAG, "surfaceCreated camera id" + mCamera);

        try {
            CamcorderProfile profile ;

            int numCameras = Camera.getNumberOfCameras();
            if (numCameras > 1) {
            profile = (CamcorderProfile
                        .get(Camera.CameraInfo.CAMERA_FACING_FRONT,CamcorderProfile.QUALITY_HIGH));
            }
            else{

                profile = (CamcorderProfile
                        .get(Camera.CameraInfo.CAMERA_FACING_BACK,CamcorderProfile.QUALITY_HIGH));
            }


            Camera.Parameters parameters = mCamera.getParameters();
            parameters.setPreviewSize(profile.videoFrameWidth, profile.videoFrameHeight);
            mCamera.setParameters(parameters);
            mCamera.setPreviewDisplay(holder);
            mCamera.startPreview();
        }
        catch (IOException e) {
            Log.d(TAG, "Error setting camera preview: " + e.getMessage());
        }}
0

精彩评论

暂无评论...
验证码 换一张
取 消