Closed MarcAragones closed 9 years ago
I am having same issue. Did you solved it?
?. Have you run debugger. Dev console. Will show any conflicts. If height= height > 0 Else} Height=1
Developer's console will point out any arguments. Android studio is rich in knowledge. Some devices do not work the same. Code is slightly different.
I could solve it by changing the default width and height:
int width = drawable.getIntrinsicWidth();
width = width > 0 ? width : 96; // Replaced the 1 by a 96
int height = drawable.getIntrinsicHeight();
height = height > 0 ? height : 96; // Replaced the 1 by a 96
public static Bitmap drawableToBitmap (Drawable drawable) {
if (drawable instanceof BitmapDrawable) {
return ((BitmapDrawable)drawable).getBitmap();
}
int width = drawable.getIntrinsicWidth();
width = width > 0 ? width : 96; // Replaced the 1 by a 96
int height = drawable.getIntrinsicHeight();
height = height > 0 ? height : 96; // Replaced the 1 by a 96
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;
}``
TextDrawable drawable = TextDrawable.builder()
.buildRoundRect("A", Color.RED, 10); // radius in px
Drawable d = new BitmapDrawable(drawableToBitmap(drawable));
When I try to setImageDrawable on API 16 inside ActionBar ImageView crashing The I have converted to Bitmap and setImageBitmap is working.
android.graphics.Rect.<init> (Rect.java:72)
android.graphics.drawable.ShapeDrawable.mutate (ShapeDrawable.java:377)
android.widget.ImageView.applyColorMod (ImageView.java:1150)
android.widget.ImageView.updateDrawable (ImageView.java:684)
android.widget.ImageView.setImageDrawable (ImageView.java:398)
android.support.v7.widget.AppCompatImageView.setImageDrawable (AppCompatImageView.java:99)
Thanks @MarcAragones , @goodlifechris
Hello, I am trying to generate a
Bitmap
fromTextDrawable
but the final result has no text, only appears the background.Here is my declaration and the function I use:
Do you know any way to do it?