赞
踩
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);
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。