Android Camera Parameters setJpegQuality deprecated? Custom camera application

2.4k views Asked by At

I'm building a custom camera application for Android. The Camera.Parameters API contains methods like setPreviewSize or setPictureSize, that are working well.

But I am trying to use setJpegQuality(int) parameter:

    Camera cam = getCameraInstance();
    if(cam == null){
        setResult(INSTANCE_ERROR);
        finish();
    }

    params = cam.getParameters();
    params.setJpegQuality(jpegQuality); 
    cam.setParameters(params);

I am testing my application on 3 different devices : an HTC Desire Z, a Galaxy S2 and a Galaxy S4.

setJpegQuality is working on HTC (Android 2.2.1) and on Galaxy S2 (4.1.2), but fails on Galaxy S4 device (4.2.2).

So my question : Is this function deprecated ? Is there another way to set picture quality ? On the Developer documentation it doesnt seems to be a deprecated function so i am a little confused...

I also tried

params.set("jpeg-quality", jpegQuality);

But its the same :(

Thanks for the answers.

3

There are 3 answers

0
macTAR On

Sorry I didnt see answers finaly come :) I dont even use this not working parameters anymore

I found a solution to set the quality of my picture, when i save it as file :

FileOutputStream fos = new FileOutputStream(finalFilePath);
bmp.compress(Bitmap.CompressFormat.JPEG, jpegQuality, fos);

Hope it helps

0
TheAndroidFreak On

For S3 and S4, you can write device specific code to reduce the size of file.

If you search on google, Android dev team also mentioned that it all depends on the implementation by the manufacturer(https://code.google.com/p/android/issues/detail?id=8091). The implementation of the camera parameters and function totally depends on the hardware used I think.

I had used motion sensors for one of my apps. There also, I had to write device specific code, to get the required behaviour in the app.

I know its not what we expect as a developer, but i believe we, developers, can fix anything. :)

0
Dan J On

I use the CWAC-Camera library for my custom camera. I forked the main repository and added a jpegQuality parameter to the PictureTransaction:
https://github.com/cookbrite/cwac-camera/commit/65a0a2082194dfc8069f605f0191c43357bb0852

This ensures that the resulting picture is always compressed to the required quality.

One drawback with this approach is that it has to load and compress the full size image file in application code, whereas using setJpegQuality on the Camera.Parameters may be more optimized.