将文本转换为位图(像素)在Android [英] Convert Text To Bitmap(Pixel) on Android
本文介绍了将文本转换为位图(像素)在Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Android应用程序中,我需要从一个网站下载的文本,将其转换成位图格式和基于LED的显示板显示。
我挣扎与位图转换。
尝试使用以下内容:
位图MYBITMAP = Bitmap.createBitmap(100,16,Bitmap.Config.ALPHA_8);
帆布C =新的Canvas(MYBITMAP);
c.drawText(0,0,0,油漆);
但它似乎并不奏效。有什么建议?
更新:
漆对象是这样初始化的:
油漆涂料=新的油漆();
paint.setStyle(Paint.Style.FILL);
paint.setColor(Color.RED);
paint.setTextSize(16);
paint.setAntiAlias(真正的);
paint.setTypeface(Typeface.MONOSPACE);
解决方案
我觉得你画的图像外。尝试设置y以 16
。
c.drawText(0,0,16,油漆);
需要注意的是绘制文本时的坐标原点是左下角坐标的角落。
I have an android application in which I need to download text from a website, convert it into bitmap format and display it on an LED-based display board.
I am struggling with the bitmap conversion.
Tried to use the following:
Bitmap mybitmap = Bitmap.createBitmap(100, 16, Bitmap.Config.ALPHA_8);
Canvas c = new Canvas(mybitmap);
c.drawText("0", 0, 0, paint);
But it doesn't seem to be working. Any suggestions?
Update:
Paint object is initialized like this:
Paint paint = new Paint();
paint.setStyle(Paint.Style.FILL);
paint.setColor(Color.RED);
paint.setTextSize(16);
paint.setAntiAlias(true);
paint.setTypeface(Typeface.MONOSPACE);
解决方案
I think you draw outside the image. Try setting y to 16
.
c.drawText("0", 0, 16, paint);
Note that when drawing text the coordinate origin is the lower left coordinate corner.
这篇关于将文本转换为位图(像素)在Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文