Convert text to bitmap (Pixel) on Android

I have an Android app in which I need to download text from a website, convert it to a raster image format and display it on the LED panel.

I am struggling with 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 does not seem to work. Any suggestions?

Update:

The Paint object is initialized as follows:

 Paint paint = new Paint(); paint.setStyle(Paint.Style.FILL); paint.setColor(Color.RED); paint.setTextSize(16); paint.setAntiAlias(true); paint.setTypeface(Typeface.MONOSPACE); 
+7
source share
1 answer

I think you are drawing outside the image. Try setting y to 16 .

 c.drawText("0", 0, 16, paint); 

Note that when drawing text, the origin is the bottom left coordinate angle.

+5
source

All Articles