SVG 转换器

SVG 是可缩放矢量图形。这是一种矢量图像格式,用于创建可放大或缩小而不会降低质量的图形和图像。SVG 图像使用 XML 代码创建,这些代码描述了组成图像的形状、路径、线条和颜色。

Aspose.HTML 的主要功能之一是其转换功能。Aspose.HTML for Java 通过其 Converter类提供了轻松访问转换方法的途径,该类是用于大多数常见转换场景的共享面板,可将 SVG 转换为各种流行格式,如 PDFXPSJPGPNGBMPTIFFGIF

如何在 Java 中转换 SVG

SVG 转换器 “一章中的文章介绍了支持的 SVG 转换列表以及如何使用 Converter 类执行转换。

要转换 SVG,需要采取几个步骤:

  1. 安装 Aspose.HTML for Java 库
  2. 使用 SVGDocument() 构造函数之一初始化 SVGDocument 类的新实例。
  3. 创建一个 SaveOptions 对象,指定所需的输出格式和转换选项。
  4. 调用 convertSVG() 方法之一,并向其传递必要的参数。

请查看以下 Java 代码片段,其中显示了使用 convertSVG(document, options, savePath) 方法将 SVG 转换为 GIF 的过程。

 1// Convert SVG to GIF in Java
 2
 3// Prepare SVG code and save it to a file
 4String code = "<svg xmlns='http://www.w3.org/2000/svg'>\n" +
 5        "<circle cx='50' cy='50' r='40' stroke='black' stroke-width='3' fill='red' />\n" +
 6        "</svg>\n";
 7try (java.io.FileWriter fileWriter = new java.io.FileWriter("document.svg")) {
 8    fileWriter.write(code);
 9}
10
11// Initialize an SVG document from the SVG file
12SVGDocument document = new SVGDocument("document.svg");
13
14// Initialize ImageSaveOptions
15ImageSaveOptions options = new ImageSaveOptions(ImageFormat.Gif);
16
17// Convert SVG to GIF
18Converter.convertSVG(document, options, "output.gif");

热门 SVG 转换器

Aspose.HTML 提供免费的在线 SVG 转换器 用于将 SVG 文件转换为各种流行格式。您可以轻松地将 SVG 转换为 PDFSVG 转换为 XPSSVG 转换为 PNGSVG 转换为 JPG 等。选择要转换的文件和格式,就大功告成了。速度快,完全免费!

您可以从 GitHub 下载完整的 Java 示例和数据文件。

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.