在扩展Android的SVGs? [英] Scaling SVGs in Android?
问题描述
我想使用这个库的http:// code .google.com / p / SVG-的Android / 得到SVGs进入Android系统。
I'm trying to use this library http://code.google.com/p/svg-android/ to get SVGs into android.
下面是我的code迄今:
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());
}
}
和它绘制SVG pretty不错。但我无法找到一个方法如何通过100像素扩展它,例如,如果我希望它是,比方说,100?
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?
任何想法?
推荐答案
在吸引他们到一个画布,您可以轻松扩展svgs。所以一个可能的解决办法是在所希望的大小的位图来创建画布,应用规模操作,然后使图像到它
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.
使用svg.getPicture()而不是getPictureDrawable。计算所需的大规模应用基于svg.getLimits()(未经svg.getBounds())。
Use svg.getPicture() instead of getPictureDrawable. Calculate the needed scale to apply based on svg.getLimits() (NOT svg.getBounds()).
这篇关于在扩展Android的SVGs?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!