How to set JPEG quality when taking a picture with Camera2 API?

Hey all,

I'm trying to set the JPEG quality of a picture with Camera2Basic, but I get an unsupported exception. The only line of code I've added is:
stillCaptureBuilder.Set(CaptureRequest.JpegQuality, 90);

That's directly under set jpeg orientation in CaptureStillPicture()

I tested changing the quality in Open Camera, and that seems to work fine, I also peeked at the source code to see if I could find anything obvious, but nothing stood out.

Thanks

Best Answers

  • AdamRowe.7409AdamRowe.7409 US ✭✭
    Accepted Answer

    Thanks hpoirier!

    I learned afterwards that C# bytes are unsigned and Java bytes are signed, I think that was why it was throwing the exception.

    So you can also cast the input as an sbyte:
    stillCaptureBuilder.Set(CaptureRequest.JpegQuality, (sbyte)90);

Answers

  • AdamRowe.7409AdamRowe.7409 USMember ✭✭
    Accepted Answer

    Thanks hpoirier!

    I learned afterwards that C# bytes are unsigned and Java bytes are signed, I think that was why it was throwing the exception.

    So you can also cast the input as an sbyte:
    stillCaptureBuilder.Set(CaptureRequest.JpegQuality, (sbyte)90);

Sign In or Register to comment.