玉玊 發表於 2025-8-5 14:00:00

图像处理控件Aspose.Imaging教程:使用 C# 将 SVG 转换为 EMF

<p><img src="https://image.evget.com/attachment/keditor/image/20250805/100652_3.png"></p>
<p><strong><u>Aspose.Imaging&nbsp;</u></strong><strong><u>for .NET</u></strong>是一款深受 .NET 开发人员喜爱的图像处理 SDK,因为它灵活且易于开发人员使用。EMF 图像文件格式提供出色的打印质量和可扩展性。此外,这种图像文件格式还节省存储空间。<strong><u>Aspose.Imaging for .NET&nbsp;&nbsp;能够</u></strong>使 SVG 到 EMF 的转换变得简单且经济实惠。本教程将演示如何借助<strong><u>Aspose.Imaging&nbsp;</u></strong><strong><u>for .NET</u></strong>在 C# 中无缝地将SVG转换为EMF。请确保您已在计算机上安装 .NET,以便可以立即实现该功能。</p>
<p style="text-align: center"><span style="color: rgba(230, 126, 35, 1)"><strong>Aspose.Imaging for .NET官方正版下载,请联系Aspose官方授权代理商<span style="color: rgba(35, 111, 161, 1)">慧都科技</span></strong></span></p>
<p style="text-align: center"><span style="color: rgba(230, 126, 35, 1)"><strong><em>加入Aspose技术交流QQ群(</em></strong><em>1041253375</em><strong><em>),与更多小伙伴一起探讨提升开发技能。</em></strong></span></p>
<h2 id="image-processing-sdk---installation">图像处理 SDK - 安装</h2>
<p>我们将安装<strong>Aspose.Imaging for .NET</strong>。</p>
<p style="text-align: center"><span style="color: rgba(230, 126, 35, 1)"><strong>Aspose.Imaging for .NET官方正版下载,请联系Aspose官方授权代理商<span style="color: rgba(35, 111, 161, 1)">慧都科技</span></strong></span></p>
<p style="text-align: center"><span style="color: rgba(230, 126, 35, 1)"><strong><em>加入Aspose技术交流QQ群(</em></strong><em>1041253375</em><strong><em>),与更多小伙伴一起探讨提升开发技能。</em></strong></span></p>
<pre class="prettyprint lang-js highlighter-hljs"><code>Install-Package Aspose.Imaging</code></pre>
<h2 id="convert-svg-to-emf-in-c-programmatically">使用 C# 编程将 SVG 转换为 EMF</h2>
<p>您可以按照以下步骤开发 SVG 到 EMF 转换器:</p>
<ol>
<li>循环遍历文件数组。</li>
<li>通过调用Image.Load(inputFileName)方法加载源 SVG 文件。</li>
<li>将 SVG光栅化选项设置为与原始图像相同的页面大小。</li>
<li>初始化 EMF选项并分配 SVG 光栅化设置以进行矢量渲染。</li>
<li>Save方法将把生成的 EMF 文件保存到磁盘上。</li>
</ol>
<p>以下代码示例展示了如何以编程方式在 C# 中将 SVG 转换为 EMF:</p>
<pre class="prettyprint lang-js highlighter-hljs"><code>using Aspose.Imaging;
using Aspose.Imaging.ImageOptions;

namespace CSharp.ModifyingAndConvertingImages.CDR
{
    class CdrToPngExample
    {
      static void Main()
      {
            // The path to the documents directory.
            string dataDir = "files";
            string[] testFiles = new string[] { "Sample.svg" };
            License lic = new License();
            lic.SetLicense(dataDir+"License.lic");
            // Loop through the files array.
            foreach (string fileName in testFiles)
            {
                string inputFileName = Path.Combine(dataDir, fileName);
                string outputFileName = Path.Combine(dataDir, fileName + ".emf");
                // Load the source SVG file by calling the Image.Load(inputFileName) method.
                using (Image image = Image.Load(inputFileName))
                {
                  // Set SVG rasterization options with the same page size as the original image.
                  VectorRasterizationOptions vectorRasterizationOptions = new SvgRasterizationOptions { PageSize = image.Size };
                  // Initialize EMF options and assign the SVG rasterization settings for vector rendering.
                  EmfOptions emfOptions = new EmfOptions
                  {
                        VectorRasterizationOptions = vectorRasterizationOptions
                  };
                  // The Save method will save the resultant EMF file on the disk.
                  image.Save(
                        outputFileName,
                        emfOptions
                        );
                }
            }
      }
   }
}</code></pre>
<p>输出:</p>
<p><img src="https://image.evget.com/attachment/keditor/image/20250805/100844_3.png"></p>
<h2 id="summing-up">总结</h2>
<p>我们探索了一种可靠的方法,可以在 C# 中以编程方式将 SVG 转换为 EMF。<strong><u>Aspose.Imaging&nbsp;</u></strong><strong><u>for .NET</u></strong>是 .NET 开发人员实现自动化转换的优选方案。此外,这款图像处理 SDK 赋予程序员完全控制权,使他们能够根据自身需求扩展功能。这篇博文介绍了其基本功能。</p>
<p style="text-align: center"><span style="color: rgba(230, 126, 35, 1)"><strong>Aspose.Imaging for .NET官方正版下载,请联系Aspose官方授权代理商<span style="color: rgba(35, 111, 161, 1)">慧都科技</span></strong></span></p>
<p style="text-align: center"><span style="color: rgba(230, 126, 35, 1)"><strong><em>加入Aspose技术交流QQ群(</em></strong><em>1041253375</em><strong><em>),与更多小伙伴一起探讨提升开发技能。</em></strong></span></p><br><br>
来源:https://www.cnblogs.com/software-Development/p/19023154
頁: [1]
查看完整版本: 图像处理控件Aspose.Imaging教程:使用 C# 将 SVG 转换为 EMF