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
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.
1 Comment
Co-Gia
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.