Convert TextDrawable to Bitmap generates no text
See original GitHub issueHello, I am trying to generate a Bitmap
from TextDrawable
but the final result has no text, only appears the background.
Here is my declaration and the function I use:
Bitmap icon = Utilities.getBitmapFromUser(user);
// ...
TextDrawable userDrawable = TextDrawable.builder()
.buildRound(firstLetter, colors[i]);
// ...
public static Bitmap drawableToBitmap (Drawable drawable) {
if (drawable instanceof BitmapDrawable) {
return ((BitmapDrawable)drawable).getBitmap();
}
int width = drawable.getIntrinsicWidth();
width = width > 0 ? width : 1;
int height = drawable.getIntrinsicHeight();
height = height > 0 ? height : 1;
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return bitmap;
}
Do you know any way to do it?
Issue Analytics
- State:
- Created 8 years ago
- Comments:5
Top Results From Across the Web
How to convert a Drawable to a Bitmap? - Stack Overflow
This converts a BitmapDrawable to a Bitmap. Drawable d = ImagesArrayList.get(0); Bitmap bitmap = ((BitmapDrawable)d).getBitmap();.
Read more >Drawables overview | Android Developers
When you need to display static images in your app, you can use the Drawable class and its subclasses to draw shapes and...
Read more >TextDrawable: Draw Some Text! - Wires Are Obsolete
The Drawable framework in Android is a neat and really flexible way to create portions of your UI. Many times have I been...
Read more >How to Convert Drawable to Bitmap in Android using Jetpack ...
Step by Step Implementation · Step 1: Create a New Project in Android Studio · Step 2: Adding a new color in the...
Read more >How to convert Drawable to a Bitmap in Android?
Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I could solve it by changing the default width and height: