从Android的TextView中得到位图 [英] get bitmap from textview in android

查看:260
本文介绍了从Android的TextView中得到位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得时显示一个TextView,但没有在活动中显示的TextView所绘制的位图。是这样的:

I want to get the bitmap that is drawn when a textview is displayed but without displaying the textview in the activity. something like this:

TextView t = new TextView(this);
t.forceToDrawItself();
Bitmap b=t.getViewBitmap();

这怎么可能?

推荐答案

查看#平局(画布) 将绘制整个视图到给定的画布。您可以使用构造<一个href=\"http://d.android.com/reference/android/graphics/Canvas.html#Canvas%28android.graphics.Bitmap%29\"相对=nofollow> 画布(位图) 创建绘制成油画给定的位图

View#draw(Canvas) will draw the entire view into the given Canvas. You can use the constructor Canvas(Bitmap) to create a Canvas that draws into the given Bitmap.

创建所需尺寸的用位图<一href=\"http://d.android.com/reference/android/graphics/Bitmap.html#createBitmap%28int,%20int,%20android.graphics.Bitmap.Config%29\"相对=nofollow> 位图#createBitmap(INT,INT,Bitmap.Config) ,包装在一个画布,并把它传递到您的视图的方法。

Create a bitmap of the desired size with Bitmap#createBitmap(int, int, Bitmap.Config), wrap it in a canvas, and pass it to your view's draw method.

这篇关于从Android的TextView中得到位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆