Code Monkey home page Code Monkey logo

Comments (5)

goodlifechris avatar goodlifechris commented on August 29, 2024 4
    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));

from textdrawable.

MarcAragones avatar MarcAragones commented on August 29, 2024 1

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

from textdrawable.

niteshkhatri avatar niteshkhatri commented on August 29, 2024

I am having same issue. Did you solved it?

from textdrawable.

caraus avatar caraus commented on August 29, 2024

?. 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.

from textdrawable.

drayan85 avatar drayan85 commented on August 29, 2024

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

from textdrawable.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.