使用 Aspose.Total for .NET ,您可以通过两个简单的步骤轻松地将 CGM 导出到任何 .NET 应用程序中的 SVGZ 图像。首先,通过使用 Aspose.PDF for .NET ,您可以将 CGM 导出为 JPEG。之后,通过使用 Aspose.Imaging for .NET 图像处理 API,您可以将 JPEG 转换为 SVGZ。
通过 .NET 将 CGM 文件转换为 SVGZ
- 用 Document 类打开CGM文件
- 初始化 JpegDevice 类对象并使用 Process 方法
- 使用 Image 类加载 JPEG 文件
- 使用 Save 方法将文档保存为SVGZ格式
转换要求
从命令行安装为 nuget install Aspose.Total
或通过 Visual Studio 的包管理器控制台使用 Install-Package Aspose.Total
。
或者,从 下载 获取 ZIP 文件中的离线 MSI 安装程序或 DLL。
// supports PDF, CGM, EPUB, TeX, PCL, PS, XPS, MD, MHTML, XSLFO, HTML file formats | |
// load PDF with an instance of Document | |
var document = new Document("input.pdf"); | |
// create an object of jpegDevice | |
var renderer = new JpegDevice(); | |
// convert a particular page and save the image in JPEG format | |
renderer.Process(document.Pages[1], "output.jpeg"); | |
// load JPEG file | |
var image = Image.Load("output.jpeg"); | |
// supports Dicom, Jpeg2000, Apng, Psd, Dxf, Wmf, Emz, Wmz, Tga, Svgz file formats | |
// save JPEG to PSD file format | |
image.Save("output.psd", new PsdOptions()); |
通过 C# 在单个文件中将 CGM 文件转换为 SVGZ
使用 API,您还可以将 CGM 文件转换为 SVGZ 到单个图像文件。为了转换所有页面,您可以首先将 CGM 文档渲染为一个 TIFF 文件,然后您可以将 TIFF 文件导出为 SVGZ。您可以使用 Document 类打开输入文件并创建 Resolution、TiffSettings 和 TIFF 设备对象。您可以使用 TiffDevice 类。最后,您可以使用 Image 类加载 TIFF 文件 并使用 Save 方法将其保存为 SVGZ 格式。
// supports PDF, CGM, EPUB, TeX, PCL, PS, XPS, MD, MHTML, XSLFO, HTML file formats | |
// Open PDF document | |
Document pdfDocument = new Document("input.pdf"); | |
// Create Resolution object | |
Resolution resolution = new Resolution(300); | |
// Create TiffSettings object | |
TiffSettings tiffSettings = new TiffSettings | |
{ | |
Compression = CompressionType.None, | |
Depth = ColorDepth.Default, | |
Shape = ShapeType.Landscape, | |
SkipBlankPages = false | |
}; | |
// Create TIFF device | |
TiffDevice tiffDevice = new TiffDevice(resolution, tiffSettings); | |
// Convert a particular page and save the image to stream | |
tiffDevice.Process("output.tif"); | |
// load TIFF file | |
var image = Image.Load("output.tif"); | |
// supports Dicom, Jpeg2000, Apng, Psd, Dxf, Wmf, Emz, Wmz, Tga, Svgz file formats | |
// save TIFF to PSD file format | |
image.Save("output.psd", new PsdOptions()); |
通过 C# 将 CGM 文件转换为 SVGZ
使用 API,您还可以根据需要旋转输出的 SVGZ 图像。 Image.RotateFlip 方法可用于将图像旋转 90/180/270 度并水平或垂直翻转图像。您可以指定要应用于图像的旋转和翻转类型。为了旋转和翻转图像,您可以使用 Image 类公开的工厂方法加载转换后的 JPEG 图像并调用 Image .RotateFlip 方法同时指定适当的 RotateFlipType 。
// supports PDF, CGM, EPUB, TeX, PCL, PS, XPS, MD, MHTML, XSLFO, HTML file formats | |
// load PDF with an instance of Document | |
var document = new Document("input.pdf"); | |
// create an object of jpegDevice | |
var renderer = new JpegDevice(); | |
// convert a particular page and save the image in JPEG format | |
renderer.Process(document.Pages[1], "output.jpeg"); | |
// load JPEG file | |
var image = Image.Load("output.jpeg"); | |
// rotate the image | |
image.RotateFlip(RotateFlipType.Rotate270FlipNone); | |
// supports Dicom, Jpeg2000, Apng, Psd, Dxf, Wmf, Emz, Wmz, Tga, Svgz file formats | |
// save JPEG to PSD file format | |
image.Save("output.psd", new PsdOptions()); |