[英]Convert Text To Bitmap(Pixel) on Android
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.我有一个 android 应用程序,我需要从网站下载文本,将其转换为 bitmap 格式并显示在基于 LED 的显示板上。
I am struggling with the bitmap conversion.我正在为 bitmap 转换而苦苦挣扎。
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 object 初始化如下:
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
.尝试将 y 设置为
16
。
c.drawText("0", 0, 16, paint);
Note that when drawing text the coordinate origin is the lower left coordinate corner.请注意,在绘制文本时,坐标原点是左下坐标角。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.