通常,创建一个VIew的截图会通过如下代码来进行获取
decorview.setDrawingCacheEnabled(true);
Bmp = decorview.getDrawingCache();
但我们有另外一个更简单的方案
通过调用View.draw(Canvas c)即可把View绘制到一个Canvas上,
public static Bitmap getViewBitmap(View v) {
Bitmap bit = Bitmap.createBitmap(v.getMeasuredWidth(),
v.getMeasuredHeight(), Config.ARGB_8888);
Canvas c = new Canvas(bit);
v.draw(c);
return bit;
}
本文介绍了一种简化View截图的方法,通过直接将View绘制到Canvas上,从而避免了使用drawingCache属性来获取View的截图。

被折叠的 条评论
为什么被折叠?



