简体   繁体   中英

Android NDK return byte array of bitmap's pixels

I have to do some processing of a bitmap, and I'm trying to use NDK to return a byte array to java by locking Bitmap pixels. After processing in java is done, I ( finally ) call another NDK function to unlock bitmap's pixels.

I've tryied a few things but no one has worked:

  • returning to java the void* returned by lock pixels operation (casting it as jbyteArray), didn't work (sigsegv).
  • Using a ByteBuffer also didnt work because its read only (I need to manipulate it from java).
  • All other approaches that seem to work, will create a copy of the array... I'm trying to avoid this in order to reduce memory consumption.

Ive solved this by manipulating the array entirely inside native code. All Java code that used the byte[] has been moved to JNI.

According to my research, I think there is no way to manipulate the byte array of a Bitmap directly from Java. Of course you can manipulate a copy, but I dindt find any way to work directly with the native bitmap's data.

If someone finds a way, I would like to know it.

Regards!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM