How to show a subsection or “slice” of an SVG graphic?

牧云@^-^@ 提交于 2019-12-06 07:39:09

问题


Is there any way to slice an SVG . I mean any already available lib . I need to implement this slicing component in Java.

I mean , I have single SVG file and based rulers/scales i choose graphically , I want to slice the single SVG into different SVG files.

Hope I am clear


回答1:


Yes, although, you'd think this was classified information - or just simply impossible - based on how hard it is to find this basic fact....

Apparently, all you need to do is reference the viewBox from a URI "fragment".. I have confirmed, it does indeed work. Take the following example... The lesson of the story, in case you miss it, is... image.svg#svgView(viewBox(100,100,100,100))

image.svg is defined as <svg .... viewBox="0,0,400,400" width="400" height="400">

http://example.com/image.svg

http://example.com/image.svg#svgView(viewBox(100,100,100,100))




回答2:


If you're working with SVG in Java, the Batik SVG Toolkit will provide a lot of functionality (I confess I don't know what you mean by slicing, however)




回答3:


All you have to do is edit the <svg> tag. Edit width and height, set the viewBox attribute on the main svg element to the rectangle you want, render, repeat.

Each svg will contain all the data from the original but will only display the part of the drawing inside the viewBox. See http://dingoskidneys.com/~dholth/svg/

viewbox = "x y width height"


来源:https://stackoverflow.com/questions/1098317/how-to-show-a-subsection-or-slice-of-an-svg-graphic

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