Skip to content

Instantly share code, notes, and snippets.

@abilogos
Created March 14, 2020 09:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abilogos/86b519a437931d321747b7bd5db80136 to your computer and use it in GitHub Desktop.
Save abilogos/86b519a437931d321747b7bd5db80136 to your computer and use it in GitHub Desktop.
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);
paint.setTextSize(textSize);
paint.setColor(textColor);
paint.setTextAlign(Paint.Align.LEFT);
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;
}
@abilogos
Copy link
Author

The Author is:
Author Github Page

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