是否可以更改android NDK中Bitmap内的像素矩阵

时间:2012-11-23 05:36:32

标签: android android-ndk

我想替换位图的像素而不创建一个新的位图实例。是否可以更改为本地方法提供的位图的void *像素而不创建新的位图实例?

1 个答案:

答案 0 :(得分:1)

根据Android NDK r8b文档(“稳定API”部分),您可以将位图传递到NDK图层并从那里处理其像素:

  

'jnigraphics'图书馆:

     

这是一个小型库,它公开了一个稳定的,基于C的接口   允许本机代码可靠地访问Java位图的像素缓冲区   对象。

     

要使用它,请在源代码中包含标题,   并链接到jnigraphics库,如:

     

LOCAL_LDLIBS + = -ljnigraphics

     

有关详细信息,请阅读以下位置的源标头:

build/platforms/android-8/arch-arm/usr/include/android/bitmap.h
     

简而言之,典型用法应如下所示:

1/ Use AndroidBitmap_getInfo() to retrieve information about a
   given bitmap handle from JNI (e.g. its width/height/pixel format)

2/ Use AndroidBitmap_lockPixels() to lock the pixel buffer and
   retrieve a pointer to it. This ensures the pixels will not move
   until AndroidBitmap_unlockPixels() is called.

3/ Modify the pixel buffer, according to its pixel format, width,
   stride, etc.., in native code.

4/ Call AndroidBitmap_unlockPixels() to unlock the buffer.