在Android中自有获取view中的cache内容,然后将内容转换成bitmap,方法名是:getDrawingCache(),返回结果为Bitmap,但是刚开始使用的时候,得到的结果都是null,所以在一个论坛里查到了正确的使用方法.代码如下:
contentLayout.setDrawingCacheEnabled(
true);
contentLayout.measure(
MeasureSpec.makeMeasureSpec(0
, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0
, MeasureSpec.UNSPECIFIED));
contentLayout.layout(0, 0
, contentLayout.getMeasuredWidth(),
contentLayout.getMeasuredHeight());
contentLayout.buildDrawingCache();
Bitmap bitmap= contentLayout.getDrawingCache();
在使用的时候调用
Bitmap bitmap = view.getDrawingCache();
就可以得到图片的bitmap了。
转载于:https://www.cnblogs.com/VACQQ/p/5870509.html
相关资源:数据结构—成绩单生成器