Convert black and white Bitmap to Single-Channel JPEG in Android

41 Views Asked by At

Is there any way to convert black and white bitmap to Single-Channel JPEG in Android?

I have a black and white bitmap that I create using ARGB_8 config. I need to send to server a Base64 of Single-Channel JPEG. I tried compressing my bitmap using Bitmap.compress(Bitmap.CompressFormat.JPEG, ...) but I always get a 3-channel image. I tried using ALPHA_8, but because it uses a transparency layer when I compress it to JPEG it is simply ignored.

Appreciate any help!

1

There are 1 best solutions below

0
user3344003 On

I can think of two approaches.

(1) Use Libjpeg for Java. Its interface will probably allow you to do what you want. Are there any similar libjpeg API in Java?

(2) You could write a filter for your JPEG stream that strips out the all zero scans for the Cb and Cr components and edits the other markers for make it look like there is only one component.