我用skia图形库中的函数画出了简单的图形,想进行缩放,查看api找到了scale()这个函数,结果模拟器上什么都没显示出来。求高手指点!!!
JNIEXPORT void JNICALL Java_com_jinpic_MainActivity_convertToGray1(JNIEnv* env,jobject obj,jobject bitmap){
AndroidBitmapInfo info;
int* pixels;
int ret;
ret = AndroidBitmap_getInfo(env, bitmap, &info);
ret = AndroidBitmap_lockPixels(env, bitmap, (void**)&pixels);
int width=(int)info.width;
int height=(int)info.height;
SkBitmap bmp = SkBitmap();
bmp.setConfig(SkBitmap::kARGB_8888_Config,width,height,0);
bmp.setPixels((void*)pixels);
SkCanvas backgroud(bmp);
backgroud.save();
backgroud.scale(100, 200);
SkPaint paint;
paint.setARGB(255, 255, 0, 0);
SkRect r;
const SkRect rect={0,0,width,height};
r.set(25, 25, 145, 145);
backgroud.drawRect(r, paint);
backgroud.drawRect(r, paint);
paint.setARGB(255, 0, 255, 0);
r.offset(20, 20);
backgroud.drawRect(r, paint);
paint.setARGB(255, 0, 0, 255);
r.offset(20, 20);
backgroud.drawRect(r, paint);
paint.setARGB(255, 0, 0, 0);
paint.setARGB(125,255,0,0);
backgroud.drawLine(100,250,100,400,paint);
backgroud.drawText("ABCD", 4*sizeof(char), 0, 100 , paint);
AndroidBitmap_unlockPixels(env, bitmap);
}
------解决方案--------------------
bmp.setConfig(SkBitmap::kARGB_8888_Config,width,height,0);
最后一个参数是设置像素大小,argb为四个字节,应该设为width*4
backgroud.scale(100, 200);
第一个参数是x的倍数,第二个参数是Y的倍数,设置的太大会不会超出farmbuffer的大小