Convert Text To Bitmap(Pixel) on Android

拈花ヽ惹草 提交于 2019-12-04 11:33:07

问题


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);

回答1:


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.



来源:https://stackoverflow.com/questions/6141268/convert-text-to-bitmappixel-on-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!