//布局转成图片
public static Drawable LayoutToDrawable(Context context, View view) {
view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight()); // 原始大小
// view.buildDrawingCache();
// Bitmap bitmap = view.getDrawingCache();
Bitmap b = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
view.draw(c);
BitmapDrawable drawable = new BitmapDrawable(context.getResources(), b);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
return drawable;
}
android – 使用getDrawingCache时是否存在最大...
网友评论