安卓定制的相机质量(Android Custom Camera Quality)

2019-07-31 22:57发布

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..

Answer 1:

当您使用getSupportedPictureSizes()它并不一定以任何顺序返回。 它可能返回一个可怕的尺寸sizes.get(0) 如果你想要最好的质量应该比较他们找到的最大尺寸。 就像是:

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);


文章来源: Android Custom Camera Quality