最后调试了半天,终于成功了
最后有用的代码
public static Bitmap loadBitmapFromView(View v) {
if (v == null) {
return null;
}
int intw=View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED);
int inth=View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED);
v.measure(intw, inth);
Bitmap bitmap = Bitmap.createBitmap(v.getMeasuredWidth(),v.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.drawColor(Color.WHITE);
v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
v.draw(canvas);
return bitmap;
}