/ Published in: Java
This method draws a specified string to a Bitmap with the desired text width and text size.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// Get text dimensions textPaint.setTextSize(textSize); StaticLayout mTextLayout = new StaticLayout(text, textPaint, textWidth, Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false); // Create bitmap and canvas to draw to Bitmap b = Bitmap.createBitmap(textWidth, mTextLayout.getHeight(), Config.RGB_565); // Draw background c.drawPaint(paint); // Draw text c.save(); c.translate(0, 0); mTextLayout.draw(c); c.restore(); return b; }