Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Android Java Development in case of Using an Layout Element that hasnot text attribute, a string can convert to an bitmap
//method to convert your text to image
public static Bitmap textAsBitmap(String text, float textSize, int textColor) {
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
float baseline = -paint.ascent(); // ascent() is negative
int width = (int) (paint.measureText(text) + 0.0f); // round
int height = (int) (baseline + paint.descent() + 0.0f);
Bitmap image = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(image);
canvas.drawText(text, 0, baseline, paint);
return image;
Copy link

abilogos commented Mar 14, 2020

The Author is:
Author Github Page

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment