开发者

How to call postinvalidate from android native code on bitmap

开发者 https://www.devze.com 2023-02-11 11:33 出处:网络
I have a bitmap created from java code and updating the pixels from native code. I was just wondering if we can call invalidate from the native code.

I have a bitmap created from java code and updating the pixels from native code. I was just wondering if we can call invalidate from the native code.

My code is as follows.

C Code :

AndroidBi开发者_JAVA技巧tmapInfo  info;
void*              pixels;
int                ret;

if ((ret = AndroidBitmap_getInfo(env, bitmap, &info)) < 0) {
return;
}

if (info.format != ANDROID_BITMAP_FORMAT_RGB_565) {
return;
}

if ((ret =AndroidBitmap_lockPixels(env, bitmap, &pixels)) < 0) {
}

memcpy(pixels, pictureRGB, 480*320);

AndroidBitmap_unlockPixels(env, bitmap);

Java Code

     Bitmap mBitmap = Bitmap.createBitmap(480, 320, Bitmap.Config.RGB_565);
     renderbitmap(mBitmap, 0);
     canvas.drawBitmap(mBitmap, 0, 0, null);


What is invalidate? Which function is implemented with the above C code?


The only possible answer I got from internet is using env pointer and use it as env->postInvalidate();


If your native code is doing an atomic operation, it would be easier to just call postInvalidate() from your Java code.

renderbitmap(mBitmap, 0);
postInvalidate();

Also you should consider having your native code work directly on the bitmap memory instead of allocating another block of memory and then having to memcpy() it into your bitmap. This hurts performance by poorly utilizing the CPU cache.

0

精彩评论

暂无评论...
验证码 换一张
取 消