javaandroidsvgsvg-android

Scaling SVGs in Android?


I'm trying to use this library http://code.google.com/p/svg-android/ to get SVGs into android.

Here's my code so far:

public class main extends Activity {
    /** Called when the activity is first created. */

    ImageView iv;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        iv = (ImageView)findViewById(R.id.imageView1);
        SVG svg = SVGParser.getSVGFromResource(getResources(), R.raw.android);
        iv.setImageDrawable(svg.createPictureDrawable());

    }
}

And it does draw the SVGpretty good. But I couldn't find a way how to scale it, for example if I want it to be, say, 100 by 100 px?

Any ideas?


Solution

  • You can easily scale svgs when you draw them into a Canvas. So a possible solution is to create a Canvas over a bitmap of the desired size, apply the scale operation and then render the picture to it.

    Use svg.getPicture() instead of getPictureDrawable. Calculate the needed scale to apply based on svg.getLimits() (NOT svg.getBounds()).