在JNI下面使用drawBitmap這函式
建立了一個專案,為YUV player在Android 2.2可以正常跑
但是在Android 4.2.2無易做图常跑
以下是我的JNI code
void Java_com_whtr_example_skiademo_SkiaView_renderHello(JNIEnv *env, jobject thizz, jobject canvas, jint FrameNum,jobject rect,jstring filename)
{
jclass bitmapConfig = env->FindClass("android/graphics/Bitmap$Config");
jfieldID rgb565FieldID = env->GetStaticFieldID(bitmapConfig, "ARGB_8888", "Landroid/graphics/Bitmap$Config;");
jobject rgb565Obj = env->GetStaticObjectField(bitmapConfig, rgb565FieldID);
jclass bitmapClass = env->FindClass("android/graphics/Bitmap");
jmethodID createBitmapMethodID = env->GetStaticMethodID(bitmapClass,"createBitmap", "(IILandroid/graphics/Bitmap$Config;)Landroid/graphics/Bitmap;");
jobject bitmapObj = env->CallStaticObjectMethod(bitmapClass, createBitmapMethodID, 352, 288, rgb565Obj);//width,height
const char *file_select= env->GetStringUTFChars(filename,NULL);
int a[101376]={0};
AndroidBitmapInfo info;
int* pixels;
int ret;
ret = AndroidBitmap_getInfo(env, bitmapObj, &info);
ret = AndroidBitmap_lockPixels(env, bitmapObj, (void**)&pixels);
int width=(int)info.width;
int height=(int)info.height;
SkBitmap bmp = SkBitmap();
bmp.setConfig(SkBitmap::kARGB_8888_Config,width,height);
bmp.setPixels((void*)pixels);
SkCanvas background(bmp);
SkCanvas* canv = GraphicsJNI::getNativeCanvas(env, canvas);
if (!canv)
{
LOGE("!canv");
return;
}
systemPara sys;
sys.width = 352;
sys.height = 288;
sys.frameNO = 1;
sys.startFrm = 0;
//sys.inFileName = new char[strlen("/mnt/sdcard/out_352x288_P420_final.yuv")+1];
//strcpy(sys.inFileName, "/mnt/sdcard/out_352x288_P420_final.yuv");
sys.inFileName=new char[strlen(file_select)+1];
strcpy(sys.inFileName,file_select);
LOGD("sys filename:%s\n",sys.inFileName);
for(int i=0;i<sys.frameNO;i++){
//sys.startFrm = i;
YUV_play_read(cur_image_y, cur_image_u, cur_image_v, sys.inFileName, sys.width, sys.height, FrameNum);
for(int x=0;x<sys.width;x++){
for(int y=0;y<sys.height;y++){
//cur_image_y[x + y * 352] = 0;
a[x + y * 352] = color(cur_image_y[x + y * 352], cur_image_u[x + y * 352], cur_image_v[x + y * 352],x,y);
}
}
}
LOGD("frame:%d\n",FrameNum);
pixels = a;
bmp.setPixels((void*)pixels);
AndroidBitmap_unlockPixels(env, bitmapObj);
LOGD("bmp.width= %d bmp.height= %d bmp.rowbytes= %d\n",bmp.width(),bmp.height(),rowBytes());
canv->drawBitmap(bmp, 0, 0, NULL);
env->ReleaseStringUTFChars(filename,file_select);
}
逐行去trace
發現有一行的行為Android 2.2跟Android 4.2.2不同
我播放的YUV檔案大小是352x288影像
在Android 2.2
LOGD("bmp.width= %d bmp.height= %d bmp.rowbytes= %d\n",bmp.width(),bmp.height(),rowBytes());
bmp 的width為352,height為288,此跟設定預期的一樣
但Android 4.2.2
LOGD("bmp.width= %d bmp.height= %d bmp.rowbytes= %d\n",bmp.width(),bmp.height(),rowBytes());
bmp 的width為1408,height為352,此跟設定預期的不同
code完全沒做修改
不知道問題出在哪裡
--------------------编程问答-------------------- 怎么是 traditional Chinese。 楼主from台湾?
把错误贴出来,才能找到切入点。 --------------------编程问答-------------------- 你好
code可以執行
並且不會發生任何錯誤訊息
但畫面是全黑的
若是在Android 2.2
畫面會正常顯示
补充:移动开发 , Android