Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
要在 C# 中将 SVGZ 转为 SVG,请用
SVGDocument 加载 .svgz 文件,并使用 SVGSaveFormat.SVG 保存。Aspose.SVG for .NET 会读取 GZIP 压缩的 SVGZ 内容,并写出同一份矢量标记作为未压缩、可编辑的 .svg 文件。
当需要检查 XML 标记、在文本工具中编辑、使用不支持 .svgz 的软件,或准备要求普通 SVG 的流程时,请将 SVGZ 转为 SVG。
SVGZ 不是另一种绘图语言,而是以 GZIP 压缩形式保存的 SVG 标记。压缩的 .svgz 适合传输和存储,未压缩的 .svg 更适合阅读、编辑、比较、验证和兼容性处理。
如果目标只是渲染压缩文件,通常无需先转为 SVG。Aspose.SVG for .NET 可直接加载 SVGZ 并渲染为 PDF 或图像。
| 场景 | SVG 输出的作用 |
|---|---|
| 手动编辑 SVG 标记 | SVG 是 XML 文本,SVGZ 是压缩二进制数据。 |
| 调试渲染、样式或字体 | 未压缩 SVG 更容易检查和比较。 |
| 使用不支持 SVGZ 的工具 | 很多 SVG 工具支持 .svg 但不支持 .svgz。 |
| 内联到 HTML 或 JavaScript | 内联使用需要 SVG 标记,而不是压缩字节。 |
1using Aspose.Svg.Saving;
2using System.IO;1// Convert a compressed SVGZ file to SVG format in C#
2
3// Load an SVG document
4using (SVGDocument document = new SVGDocument(Path.Combine(DataDir, "shapes.svgz")))
5{
6 // Save the document as SVG
7 document.Save(Path.Combine(OutputDir, "shapes.svg"), SVGSaveFormat.SVG);
8}1using Aspose.Svg.Saving;
2using System.IO; 1// Convert multiple SVGZ files to SVG format in C#
2
3// Loop through all .svgz files in the input directory
4foreach (string svgzFile in Directory.GetFiles(DataDir, "*.svgz"))
5{
6 try
7 {
8 // Extract the file name without extension to use for the output file
9 string fileNameWithoutExt = Path.GetFileNameWithoutExtension(svgzFile);
10
11 // Construct the output path with .svg extension
12 string outputPath = Path.Combine(OutputDir, fileNameWithoutExt + ".svg");
13
14 // Load the compressed SVGZ file
15 using (SVGDocument document = new SVGDocument(svgzFile))
16 {
17 // Save it as a standard uncompressed SVG file
18 document.Save(outputPath, SVGSaveFormat.SVG);
19 }
20
21 // Log successful conversion
22 Console.WriteLine($"Converted: {fileNameWithoutExt}.svgz → {fileNameWithoutExt}.svg");
23 }
24 catch (Exception ex)
25 {
26 // Log any errors that occurred during conversion
27 Console.WriteLine($"Failed to convert {svgzFile}: {ex.Message}");
28 }
29}并非所有应用都能读取 SVGZ。某些构建流程或图像处理器可能忽略或错误处理它。由于 SVGZ 是二进制格式,不能直接在文本编辑器中调试或编辑。
| 问题 | 常见原因 | 解决方法 |
|---|---|---|
| 转换后的 SVG 比 SVGZ 大 | SVGZ 被压缩,SVG 是未压缩 XML | 这是正常现象。编辑用 SVG,分发或存储用 SVGZ。 |
| 输出 SVG 引用缺失的图片或 CSS | 源 SVGZ 包含外部资源引用 | 保持资源可访问,或单独保存和处理资源。 |
| 批量转换因一个文件停止 | 异常没有按文件处理 | 在每个文件级别捕获错误。 |
| 渲染前不必要地转为 SVG | 渲染 API 可直接加载 SVGZ | 只有需要编辑、调试、兼容或比较时才转换。 |
SVGZ 转 SVG 会改变图形吗?
不会。转换只是解压标记,矢量内容保持不变。
可以直接编辑 SVGZ 吗?
不方便。先转为 SVG,再编辑 XML、检查样式或比较更改。
转 PDF 或 PNG 前必须先转为 SVG 吗?
不需要。Aspose.SVG for .NET 可以直接加载 SVGZ 并渲染。
Aspose.SVG 提供免费的在线 SVG Converter,可转换 SVG 到多种常见格式。
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.