简体   繁体   English

如何调整svg(使用蜡染)并显示它?

[英]How to resize an svg (with batik) and display it?

I have a svg file of 100x100 pixels (for example). 我有一个100x100像素的svg文件(例如)。 I am using Batik. 我正在使用Batik。

If I do a : 如果我这样做:

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

It will only show this part of the picture and not the resized image. 它只会显示图片的这一部分,而不会显示已调整大小的图像。

Do you know how I can display a resized svg picture ? 你知道我怎么能显示调整大小的svg图片吗?

Thanks ;) 谢谢 ;)

You need to ensure that the document you are displaying has a viewBox="" attribute set on its root <svg> element. 您需要确保您显示的文档在其根<svg>元素上设置了viewBox=""属性。 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 . 例如,指定viewBox="100 100 300 200"表示区域(100,100)→(400,300)将缩放为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 . 默认情况下,缩放时将保留此区域的宽高比,因此如果它与JSVGCanvas的宽高比不匹配,则会在顶部或底部获得一些额外的填充。 To override that behaviour, use the preserveAspectRatio="" attribute. 要覆盖该行为,请使用preserveAspectRatio=""属性。

The view box parameter allows you to set the part of the canvas you want to see/display. 视图框参数允许您设置要查看/显示的画布部分。 If you want to "resize" your svg (an svg has no real size, because it is a vector image), you can add/change the parameters width and height present in the <svg> header like this : 如果你想“调整大小”你的svg(svg没有真正的大小,因为它是一个矢量图像),你可以添加/更改<svg>标题中存在的参数widthheight ,如下所示:

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" contentScriptType="text/ecmascript" zoomAndPan="magnify" width="1200" height="720" contentStyleType="tex ....</svg>

If you want to change the view box, you can add the parameter 如果要更改视图框,可以添加参数

viewBox="0 0 1200.0 720.0" 

in the <svg> header (for a HD view of 1200 by 720). <svg>标题中(对于1200 x 720的高清视图)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM