Is there any way to convert internal storage image into android Drawable Object

0

I had to use this drawable object in my code. but I created those objects with my project resource images. I want to get drawable objects with internal storage images or online images. here is my sample code that I used my Drawable object

public Bitmap getBitmap(int width, int height, int index) {
            Bitmap b = Bitmap.createBitmap(width, height,
                    Bitmap.Config.ARGB_8888);
            b.eraseColor(0xFFFFFFFF);
            Canvas c = new Canvas(b);
            Drawable d = getResources().getDrawable(mBitmapIds[index]);

            int margin = 1;
            int border = 1;
            Rect r = new Rect(margin, margin, width - margin, height - margin);

            int imageWidth = r.width() - (border * 2);
            int imageHeight = imageWidth * d.getIntrinsicHeight()
                    / d.getIntrinsicWidth();
            if (imageHeight > r.height() - (border * 2)) {
                imageHeight = r.height() - (border * 2);
                imageWidth = imageHeight * d.getIntrinsicWidth()
                        / d.getIntrinsicHeight();
            }

            r.left += ((r.width() - imageWidth) / 2) - border;
            r.right = r.left + imageWidth + border + border;
            r.top += ((r.height() - imageHeight) / 2) - border;
            r.bottom = r.top + imageHeight + border + border;

            Paint p = new Paint();
            p.setColor(0xFFC0C0C0);
            c.drawRect(r, p);
            r.left += border;
            r.right -= border;
            r.top += border;
            r.bottom -= border;

            d.setBounds(r);
            d.draw(c);
            return b;
        }
android
image
converters
asked on Stack Overflow Jan 19, 2020 by Lasitha Lakmal

1 Answer

0

This is my solution

Drawable d = new BitmapDrawable(getResources(), BitmapFactory.decodeStream(new URL("https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885__340.jpg").openStream()));
answered on Stack Overflow Jan 19, 2020 by Lasitha Lakmal

User contributions licensed under CC BY-SA 3.0