Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
like image 666
Neha Avatar asked May 26 '11 15:05

Neha


1 Answers

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.

like image 118
dacwe Avatar answered Sep 23 '22 23:09

dacwe