Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I don't know if this is the best way, and I haven't done it before... but here's how I'd do it:</p> <ul> <li>Create a <code>Paint</code> object that will describe the appearance of the text.</li> <li>Set the required parameters for font (<code>Paint.setTypeFace()</code>), size (<code>Paint.setTextSize()</code>), color, etc.</li> <li>Measure the size of the required bitmap using <code>Paint.getTextBounds()</code> and the string you want to draw.</li> <li>Create a new bitmap of that size using <code>Bitmap.createBitmap()</code>, make sure it has an alpha component.</li> <li>Create a canvas using the bitmap you created to draw into using <code>new Canvas(bitmap)</code>.</li> <li>Draw the text into the bitmap: <code>Canvas.drawText()</code>, using the paint object you created and the string you want.</li> <li>Scale the bitmap using <code>Bitmap.createScaledBitmap()</code> to be the next larger size as a power of 2 in x and y. I have a handy function (round up to power of 2) for that if you need it.</li> <li>Bind, set texture parameters and load the bitmap to gl using <code>GLUtils.texImage2D()</code></li> <li>Draw a quad/sprite using the texture; scale appropriately using the measured text dimensions.</li> </ul> <p>Of course, if you want to do the button background/button text compositing beforehand, you can use the canvas to draw into the background instead. </p> <p>I presume that whatever fonts android supports, Canvas.drawText() will support using the appropriate Paint settings, the same should go for string characters (Kanji or other) that are input to it. It will be easy to find out by experimenting once you get the method above up and running.</p> <p>Hope this was somewhat helpful. Cheers, Aert.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload