4

I used libjpeg (C library) to decompress a JPEG file. Now I have an unsigned char array. How can I create a bitmap from that array in JNI ?

1 Answer 1

5

Yes, it's possible, but there should be a strong justification for going this path. For best performance, use

Bitmap bm = BitmapFactory.decodeByteArray(jpegArray, 0, jpegArray.length);

Even if you need to decode the same jpeg twice - once in C, once in Java, it will save you both programming effort and execution time.

Note that Android has libjpeg built in (see /system/lib on your device), and decodeByteArray() uses it, and is highly optimized.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your answer. I tried the method BitmapFactory.decodeByteArray(jpegArray, 0, jpegArray.length); but failed. I figured out this problem by passing a bitmap object to jni and filled values for that bitmap. It worked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.