Android Custom Camera Quality

给你一囗甜甜゛ 提交于 2020-01-01 10:59:09

问题


I am using the following parameters for my custom camera

mCamera = getCameraInstance();

params = mCamera.getParameters();
params.setFlashMode(Camera.Parameters.FLASH_MODE_AUTO);
params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
params.setSceneMode(Camera.Parameters.SCENE_MODE_AUTO);
params.setWhiteBalance(Camera.Parameters.WHITE_BALANCE_AUTO);
params.setExposureCompensation(0);
params.setPictureFormat(ImageFormat.JPEG);
params.setJpegQuality(100);
params.setRotation(90);

List<Size> sizes = params.getSupportedPictureSizes();
Camera.Size size = sizes.get(0);
params.setPictureSize(size.width, size.height);

mCamera.setParameters(params);

And after a photo is taken, the quality of the image is quite bad. I have autofocus and flash in use.

This is my method for taking the photo..

mCamera.autoFocus(new Camera.AutoFocusCallback() {
    ShutterCallback shutterCallback = new ShutterCallback() {

        @Override
        public void onShutter() {
            AudioManager mgr = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
            mgr.playSoundEffect(AudioManager.FLAG_PLAY_SOUND);
        }
    };

    PictureCallback pictureCallback = new PictureCallback() {

        @Override
        public void onPictureTaken(byte[] data,
                Camera camera) {
            ...
        }
    };

    public void onAutoFocus(boolean success, Camera camera) {
        mCamera.takePicture(shutterCallback,
                null, null, pictureCallback);
    }
});

It is especially bad when the flash doesn't fire (I'm using auto flash) and the room I'm in is well lit..


回答1:


When you use getSupportedPictureSizes(), it doesn't necessarily return them in any order. It's probably returning a horrible size in sizes.get(0). You should compare them to find the biggest size if you want the best quality. Something like:

List<Size> sizes = params.getSupportedPictureSizes();
Camera.Size size = sizes.get(0);
for(int i=0;i<sizes.size();i++)
{
    if(sizes.get(i).width > size.width)
        size = sizes.get(i);
}
params.setPictureSize(size.width, size.height);


来源:https://stackoverflow.com/questions/12606705/android-custom-camera-quality

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