Scaling SVGs in Android?

ⅰ亾dé卋堺 提交于 2019-12-24 10:41:34

问题


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?


回答1:


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()).



来源:https://stackoverflow.com/questions/7370567/scaling-svgs-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!