小编DaR*_*lla的帖子

如何将TextView绘制到位图中(无需在显示屏上绘制)

根据主题"将TextView截屏到位图"中找到了很多帖子.

嗯,我的问题的不同之处在于,首先在显示器上绘制视图(已完成所有布局和测量工作),然后绘制到连接到位图的Canvas.

我只是想从头开始创建一个TextView,而不是在显示器上显示,它被渲染成一个Bitmap.

这个是已经工作的基础配置.单击TextView将自身绘制到Bitmap中并将其设置为ImageView.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:orientation="vertical" android:background="#fff">

    <TextView android:id="@+id/tv" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:text="The Quick Brown Fox Jumps Over The Lazy Dog."
        android:textSize="20dip" android:background="#abcdef"
        android:textColor="#000" android:padding="10dip"
        android:layout_margin="10dip" />

    <ImageView android:id="@+id/iv" android:layout_width="449px"
        android:layout_height="47px" android:background="#56789a"
        android:layout_margin="10dip" />
</LinearLayout>

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    findViewById(R.id.tv).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Bitmap bmp = Bitmap.createBitmap(449, 47, Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(bmp);

            v.draw(canvas);

            ImageView iv = (ImageView) findViewById(R.id.iv);
            iv.setImageBitmap(bmp);
        }
    });
}
Run Code Online (Sandbox Code Playgroud)

现在是问题部分.我将在Java中创建一个TextView,我希望将其直接绘制到Bitmap中.在此之后,我将其设置为ImageView.我从没跑过这个:(

Bitmap …
Run Code Online (Sandbox Code Playgroud)

android canvas bitmap textview

9
推荐指数
1
解决办法
1万
查看次数

标签 统计

android ×1

bitmap ×1

canvas ×1

textview ×1