当前位置:   article > 正文

如何将layout 的内容转成bitmap_linearlayout 转 bitmap

linearlayout 转 bitmap

1、创建自己的layout pic_view.xml


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    
    <TextView 
        android:id="@+id/tv_msg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        
        />
  

</LinearLayout>


2、将pic_view.xml转换成bitmap

public Bitmap ConvertViewtoBitmap(String msg) {
Bitmap bitmap = null;
View view = View.inflate(mContext, R.layout.pic_view, null);

TextView tv_msg = (TextView) view.findViewById(R.id.tv_msg);
tv_msg.setTextColor(Color.BLACK);
tv_msg.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
tv_msg.setTextSize(20);

tv_msg.setText(msg);

 view.destroyDrawingCache();  
view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),  
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));  
view.setBackgroundColor(Color.WHITE);
view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());  
view.setDrawingCacheEnabled(true);  
 return view.getDrawingCache(true);

}



声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/262104
推荐阅读
相关标签
  

闽ICP备14008679号