在 Java 中缩放 SVG
我正在尝试缩放图像,修改它,然后输出到另一种图像格式。到目前为止,我一直在使用 apache batik 库。对于简单的转换来说,这很容易。对于剪切 svg,这很容易。
但是,我似乎不知道如何缩放到 svg 创建的完整图像。也就是说,我可以将感兴趣的区域指定为边界矩形,然后在边界矩形上进行缩放,但我不知道如何在 svg 图像上进行缩放。
这是我到目前为止所拥有的:
...
//set the output width and height
transcoder.addTranscodingHint( PNGTranscoder.KEY_WIDTH, new Float( newSize.width ) );
transcoder.addTranscodingHint( PNGTranscoder.KEY_HEIGHT, new Float( newSize.height ) );
//set the aoi for scaling. Unsure what to do here.
transcoder.addTranscodingHint( PNGTranscoder.KEY_AOI, new Rectangle( 0, 0, 100, 100 ) );
...
I'm attempting to scale an image, modify it, and then output to another image format. So far, I've been using the apache batik library. For simple conversion, this is easy. For clipping the svg, this is easy.
However, I can't seem to figure out how to scale to the full image created by the svg. That is, I can specify the area of interest as a bounding rectangle, and then scaling works over the bounding rectangle, but I do NOT know how to scale over the image of the svg.
This is what I have so far:
...
//set the output width and height
transcoder.addTranscodingHint( PNGTranscoder.KEY_WIDTH, new Float( newSize.width ) );
transcoder.addTranscodingHint( PNGTranscoder.KEY_HEIGHT, new Float( newSize.height ) );
//set the aoi for scaling. Unsure what to do here.
transcoder.addTranscodingHint( PNGTranscoder.KEY_AOI, new Rectangle( 0, 0, 100, 100 ) );
...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您未设置 KEY_AOI 转码提示,则根
元素上的
viewBox=""
属性将用于确定感兴趣的区域。如果您要转码的文档没有viewBox=""
属性,则width=""
和height=""
将使用 属性,因此 AOI 将为 (0, 0, width, height)。如果这些都没有设置,并且您事先不知道图形在文档坐标系中的位置,那么您可以计算根
元素的边界框并使用作为 AOI。您可以通过首先为您的文档"引导 DOM" 来完成此操作,然后调用 < code>getBBox() 在文档元素上。
If you don't set the KEY_AOI transcoding hint, then the
viewBox=""
attribute on the root<svg>
element will be used to determine the area of interest. If the document you are transcoding doesn't have have aviewBox=""
attribute, then thewidth=""
andheight=""
attributes will be used, so the AOI will be (0, 0, width, height).And if none of these are set, and you don't know in advance where within the document's coordinate system the graphics are, then you could compute the bounding box of the root
<svg>
element and use that as the AOI. You could do this by first "booting the DOM" for your document, and then callinggetBBox()
on the document element.