简体   繁体   中英

How to call postinvalidate from android native code on bitmap

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 :

AndroidBitmapInfo  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?

我从互联网上获得的唯一可能答案是使用env指针,并将其用作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.

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