如何在Java中高效地绘制SVG图像?
参考: 旋转 BufferedImage 时如何产生清晰的绘画结果?
在引用的问题中,我询问有关光栅化图像转换的质量。有人建议我应该使用 SVG 图像,因为转换的质量会更好、更灵活。 (这是正确的,是吗?)
所以我花了相当多的时间试图弄清楚如何使用 Batik 库,通读他们的 API 并谷歌搜索看看其他人是否有相同的问题。
到目前为止,我还没有遇到任何实质性的事情,所以我希望有人能帮助我。这实际上是我想做的事情:
以与使用 BufferedImages 的 AffineTransform 和 Graphics2D 的 drawImage(...) 类似的方式,
是否可以(以及如何)转换并绘制一个SVG 图像/对象到 JPanel 上?
我在想,在我想要绘制它之前,我可以先根据 AffineTransform 对象对它进行光栅化,然后使用 Graphics2D 进行绘制,但是如果我每次都必须在绘制图像之前进行光栅化......肯定有更好的方法方法。
经过深思熟虑,我想知道 SVG 是否真的是正确的选择。 那么我应该采取什么最好的方法?
光栅化图像与矢量图像。
注意:创建 SVG 文件根本不是问题。
谢谢。
Reference: How can you produce sharp paint results when rotating a BufferedImage?
In the referenced question I asked about quality regarding transformations of rasterized images. Someone suggested that I should use SVG images, as the quality of transformations will be greater and more flexible. (Which is correct, yes?)
So I've been spending quite some time trying to figure out how to use the Batik libraries, reading through their API's and googling to see if other people have had the same problem.
So far I haven't come across anything substantial, so I'm hoping that someone can help me out. Here's effectively what I'd like to do:
In a similar fashion to AffineTransform and Graphics2D's drawImage(...) using BufferedImages,
is it possible (and how) to transform and then paint an SVG image/object onto a JPanel?
I was thinking before I want to paint it, I could somehow rasterize it first according to an AffineTransform object, and then paint it using Graphics2D, but if I have to rasterize every time before I can paint an image... surely there's a better approach.
So after much thought, I'm wondering whether SVG is really the way to go here.
What's the best approach that I should take then?
Rasterized vs. Vector images.
Note: Creating the SVG files hasn't been an issue at all.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在 pdf 上下文中使用这个库(使用 jasper /iReport),结果是正确的。我尝试过蜡染,但发现它很难使用
I use this library in a pdf context (with jasper /iReport) and the result is correct. I have tried Batik but i have found it's difficult to use