k_shil
k_shil

Reputation: 2148

How to convert PictureDrawable into ScaleDrawble?

I am trying to scale a picture drwable which I get from svg-android-library. I can create the drawable but do not get how to scale it.

Here is the code I tried:

Drawable drawable = svg.createPictureDrawable();
    int size = 108;
        Bitmap img = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(img);
        //resize drawable here according to screen width
        drawable = new ScaleDrawable(drawable, 0, size*2, size*2).getDrawable();
        drawable.setBounds(0, 0, size*2, size*2);
        drawable.draw(canvas);

Any suggestions?

Upvotes: 0

Views: 879

Answers (1)

Behzad Momahed Heravi
Behzad Momahed Heravi

Reputation: 1393

I used

Picture picture = svg.getPicture();

and then draw it with a new Rect which will stretch it to fit the new Rect

canvas.drawPicture(picture, newRect);

Upvotes: 3

Related Questions