简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM