首页 > 移动平台 > 详细

Android中View转换为Bitmap及getDrawingCache=null的解决方法

时间:2015-12-03 09:47:54      阅读:356      评论:0      收藏:0      [点我收藏+]
public static Bitmap convertViewToBitmap(View view){
      view.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
        view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
        view.buildDrawingCache();
        Bitmap bitmap = view.getDrawingCache();

     return bitmap;


注意:view 使用 "getMeasuredWidth()" and "getMeasuredHeight()"方法计算长宽。此时,Bitmap就能正确获取了。

Android中View转换为Bitmap及getDrawingCache=null的解决方法

原文:http://www.cnblogs.com/BoYu045535/p/5015004.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!