Android Bit Bitmap for Native 2.1 and below

It is very easy to get bitmap data in NDK when working with Android 2.2, but with 2.1 and lower the AndroidBitmap_lockPixels function is not available. I have been looking for the past few hours, but nothing worked.

How can I access pixel data of a bitmap without using this function?

+5
source share
3 answers

Create an empty raster map with the dimensions of the source image and the format ARGB_8888:

int width =  src.getWidth();
int height = src.getHeight();
Bitmap dest = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

Copy pixels from the original bitmap to the int array:

int[] pixels = new int[width * height];
src.getPixels(pixels, 0, width, 0, 0, width, height);

And set these pixels to the target bitmap:

dest.setPixels(pixels, 0, width, 0, 0, width, height);
+1
source

Create an IntBuffer in Java code and pass the array to your native library:

// this is called from native code
buffer = IntBuffer.allocate(width*height);
return buffer.array();

GetIntArrayElements jint * :

jint * arr = env->GetIntArrayElements((jintArray)bufferArray, NULL);

, , :

env->ReleaseIntArrayElements((jintArray)bufferArray, arr, 0);

Java-, , Canvas.drawBitmap(), IntBuffer:

canvas.drawBitmap(buffer.array(), ....);

,

... new Canvas(bitmap)
+1

- - , :

Android

, , , Java JNI, , , Android 2.1 .

+1

All Articles