如何调整svg的大小(使用蜡染)并显示它? [英] How to resize an svg (with batik) and display it?

查看:140
本文介绍了如何调整svg的大小(使用蜡染)并显示它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个100x100像素的svg文件(例如). 我正在使用蜡染.

I have a svg file of 100x100 pixels (for example). I am using Batik.

如果我做一个:

JSVGCanvas svg = new JSVGCanvas();
[...]
svg.setSize(10,10);

它将仅显示图片的这一部分,而不显示调整大小后的图片.

It will only show this part of the picture and not the resized image.

您知道如何显示重新调整大小的svg图片吗?

Do you know how I can display a resized svg picture ?

谢谢;)

推荐答案

您需要确保所显示的文档的根<svg>元素上设置了viewBox=""属性.例如,指定viewBox="100 100 300 200"表示区域(100,100)→(400,300)将缩放为JSVGCanvas的大小.默认情况下,缩放时会保留该区域的长宽比,因此,如果与JSVGCanvas的长宽比不匹配,您将在顶部或底部得到一些额外的填充.要覆盖该行为,请使用 preserveAspectRatio="" 属性.

You need to ensure that the document you are displaying has a viewBox="" attribute set on its root <svg> element. For example, specifying viewBox="100 100 300 200" indicates that the region (100,100)→(400,300) will be scaled to the size of the JSVGCanvas. By default, the aspect ratio of this region will be preserved when scaling, so you will get some extra padding on the top or bottom if it doesn't match the aspect ratio of your JSVGCanvas. To override that behaviour, use the preserveAspectRatio="" attribute.

这篇关于如何调整svg的大小(使用蜡染)并显示它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆