I am facing problem with displaying bitmap using nat开发者_运维百科ive code. My code is as below
Native Code
JNIEXPORT void JNICALL Java_app_Panel_renderbitmap(JNIEnv* env, jobject obj, jobject bitmap, jlong time_ms)
{
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);
And my Application is crashing at memcpy, in which pictureRGB is declared as int *pictureRGB[4];
All the pixels are inside the pictureRGB. Is there anything wrong the way i am doing? Am passing correct values to bitmap and memcpy?
I think you should declare pictureRGB
as follows:
uint16_t *pictureRGB;
pictureRGB = malloc(sizeof(uint16_t)*480*320);
And then to copy the pixels do the following:
memcpy(pixels, pictureRGB, 480*320*sizeof(uint16_t));
精彩评论