java – Android Camera setJpegQuality ignored-ThrowExceptions

Exception or error:

It seems that the setJpegQuality method of Camera.Parameters is ignored, at least on the devices I’ve tried it with (Nexus S, Galaxy S2).

Does it work for anyone else, or is this a known issue, or am I doing something wrong, or… ?

Code for setting parameters below. jpeg quality 1 is very distinctive, so it’s very easy to determine visually whether it’s working… and it isn’t! Other parameters set here (e.g. sepia) work.

    camera = Camera.open();
    final Camera.Parameters parameters = camera.getParameters();
    parameters.setJpegQuality(1);
    parameters.setPictureFormat(ImageFormat.JPEG);
    // Let's set a SEPIA effect, just to verify these parameters are working at all!
    parameters.setColorEffect(Camera.Parameters.EFFECT_SEPIA);
    // I've seen this syntax too on the internet, presumably it's legacy.
    parameters.set("jpeg-quality", 1);
    camera.setParameters(parameters);
How to solve:

Set all attributes of the picture:

parameters.setPreviewSize(854, 480);  // (h, w)
   parameters.setPictureFormat(ImageFormat.JPEG);
   parameters.set("jpeg-quality", 100);
   parameters.set("orientation", "landscape");
   parameters.set("rotation", 90);
   mCamera.setParameters(parameters);
   mCamera.startPreview();

Leave a Reply

Your email address will not be published. Required fields are marked *