Reputation: 2348
I need to convert a void * which will be having a bitmap data. The void* is returned from a cpp function and what I need to do is to convert this void* which is passed to Jni and display this as a bitmap in Java.
Void * buffer = CppClass->getbuffer();
ByteArray byte[];
byte = the contents of void*;
Upvotes: 0
Views: 2156
Reputation: 3911
Since java do not have void*
and jni do not have ByteArray
, it's not clear what's your execution environment.
Since the source of problem is the void* pixel map, I would assume you want to create a java Bitmap object with the pixels, with a mix of JNI and Java code.
First look at the Bitmap class, there is a convenient function named copyPixelsFromBuffer
, looks like useful, it takes a Buffer.
Second, look at JNI function NewDirectByteBuffer, it takes a C pointer and create a ByteBuffer
, which is also a Buffer needed by Bitmap
.
Now it becomes clear, you just need to:
ByteBuffer
with the pixel buffer with JNI codeByteBuffer
to Java landBitmap
with such ByteBuffer
.ImageView
or your paint routine.P.S. It's left to OP's excise to handle object referencing to be GC friendly.
Upvotes: 2