在尝试制作自定义视图的屏幕截图时,我得到了IllegalArgumentException : width and height must be >0
. 这是我写的:
bitmap = loadBitmapFromView(v1);//v1 the custom view I want to picture.
public static Bitmap loadBitmapFromView(View v) {
Bitmap b = Bitmap.createBitmap( v.getLayoutParams().width, v.getLayoutParams().height, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
v.layout(0, 0, v.getLayoutParams().width, v.getLayoutParams().height);
v.draw(c);
return b;
}
有异常的那一行:Bitmap b = Bitmap.createBitmap( v.getLayoutParams().width, v.getLayoutParams().height, Bitmap.Config.ARGB_8888);
当然屏幕截图代码是在视图显示后执行的,在next_act按钮代码上