2

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.

Dan J
  • 25,433
  • 17
  • 100
  • 173
macTAR
  • 83
  • 12
  • 1
    Am I the 1st in the world to have issues with this function ? – macTAR Dec 16 '13 at 16:27
  • 2
    I am probably the second one, but couldn't find a solution. Did you find one macTar? – Prateek Sep 24 '14 at 09:49
  • I'm seeing the same issue with an S3. setJpegQuality(80) seems to work fine on my Nexus 4 (4.4.4) and HTC Sensation (4.0.3), but on the S3 the photos seem to still be at full quality, resulting in 2X bigger file sizes. – Dan J Oct 10 '14 at 20:56
  • any results on this one? – zaxy78 Oct 12 '14 at 08:57
  • 1
    could you get the value of getJpegQuality(), and how do you know that the method doesn't work? please give more infor (logcat, debug dump value etc.) – Nguyễn Hoài Nam Oct 15 '14 at 04:42
  • 1
    The function doesn't appear to be deprecated, but you are possibly facing manufacturer implementation issues. If you haven't tried it yet, try stopping the preview before setting the quality then re-starting it. I have had issues in the past where the camera "driver" only reads parameters at startup. – C B J Oct 15 '14 at 08:10
  • had you've taken into account, that maybe the photo resolution is much bigger than on the other two? – Citrus Oct 15 '14 at 20:32

3 Answers3

1

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

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.

Dan J
  • 25,433
  • 17
  • 100
  • 173
0

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

macTAR
  • 83
  • 12