I can't change android camera resolution

南笙酒味 提交于 2019-12-24 06:34:39

问题


This is my code in onPreviewFrame Method.

The frame that shows on the surfaceHolder is fine.

I Already set the resolution with this code at first

 mCameraParameter = mCamera.getParameters();
 mCameraParameter.setPreviewSize(100,150);
 mCameraParameter.setPreviewFrameRate(20);
 mCameraParameter.setPreviewFormat(PixelFormat.JPEG);
 mCamera.setParameters(mCameraParameter);

but the picture that image get is 640 * 480

I wonder why i can't change the preview resolution.

        public void onPreviewFrame(byte[] data, Camera camera) {
        Log.e("PreviewCallBack", "Preview");


        Camera.Parameters parameters = camera.getParameters();
        Log.e("Picture Size", "width : " + parameters.getPreviewSize().width);
        Log.e("Picture Size", "height : " + parameters.getPreviewSize().height);
        Log.e("Array Size", "data.length : " + data.length);
        YuvImage image = new YuvImage(data, parameters.getPreviewFormat(),
                parameters.getPreviewSize().width,parameters.getPreviewSize().height, null);


        File file = new File(Environment.getExternalStorageDirectory()
                .getPath() + "/"+/*System.currentTimeMillis()*/"out.jpg");

        FileOutputStream filecon = null;

        try {
            filecon = new FileOutputStream(file);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }


        image.compressToJpeg(
                new Rect(0, 0, image.getWidth(), image.getHeight()), 90,
                filecon);
    }
};

回答1:


Maybe you are trying to set an unsupported preview size. Better call "getSupportedPreviewSizes()" and check if the preview size you want to set is supported by your device before calling setPreviewSize().




回答2:


I think you should call setPictureSize() to set the size of the picture itself (not the preview).



来源:https://stackoverflow.com/questions/6887503/i-cant-change-android-camera-resolution

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!