Java层创建Bitmap,通过JNI将Bitmap传到C/C++进行处理
Java部分
public static native boolean greenBitmap(Bitmap bitmap);
C/C++部分
JNIEXPORT jboolean JNICALL Java_com_test_Test_greenBitmap
(JNIEnv *, jclass, jobject);
#include
JNIEXPORT jboolean JNICALL Java_com_test_Test_greenBitmap
(JNIEnv *env, jclass, jobject src)
{
unsigned char *srcData = NULL;
AndroidBitmap_lockPixels(env, src, (void**)&srcData);
AndroidBitmapInfo srcInfo;
AndroidBitmap_getInfo(env, src, &srcInfo);
int pixel = srcInfo.width * srcInfo.height;
for(int i=0;i
{
srcData [4*i] = (unsigned char)0;//red
srcData [4*i+1] = (unsigned char)255;//green
srcData [4*i+2] = (unsigned char)0;//blue
srcData [4*i+3] = (unsigned char)255;//alpha
}
AndroidBitmap_unlockPixels(env, src);
return true;
}
Android.mk
LOCAL_LDLIBS += -ljnigraphics