专业的编程技术博客社区

网站首页 > 博客文章 正文

用代码转换CAD格式工程图!AutoCAD处理控件Aspose.CAD超详演示!

baijin 2024-08-14 12:20:32 博客文章 8 ℃ 0 评论

Aspose.CAD for .NET是一个独立的AutoCAD处理API。它提供将DWG,DWF和DXF文件转换为高质量PDF和光栅图像的功能。开发人员可以从AutoCAD文件中选择和转换特定的布局和图层,并轻松跟踪整个文件转换过程。

近期Aspose.CAD for .Net更新至最新版v20.1,新增了三个非常实用的新功能——支持OBJ格式、支持将DWG转换为DWF、能够操纵AutoCAD工程图中的超链接,接下来,我们通过示例来了解新增功能!(点击文末“了解更多”下载测试)

本文将介绍如何使用Aspose.CAD将CAD工程图转换为PDF和光栅图像格式。



将CAD工程图转换为栅格图像格式

Aspose.CAD for .NET能够将CAD绘图格式(例如DXF和DWG)转换为受支持的光栅图像格式,例如PNG,BMP,TIFF,JPEG和GIF。Aspose.CAD for .NET API已公开了有效且易于使用的方法来实现此目标。

可以使用下面介绍的简单步骤将任何受支持的CAD工程图格式转换为栅格图像格式。

  1. 将CAD文件加载到Image的实例中
  2. 创建一个CadRasterizationOptions实例,并设置其必填属性,例如PageWidth 和PageHeight
  3. 创建ImageOptionsBase 的实例并将其VectorRasterizationOptions 属性设置为在上一步中创建的CadRasterizationOptions实例
  4. 呼叫Image.Save通过将文件路径(或的MemoryStream的对象)以及实例ImageOptionsBase在先前步骤中创建的
// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_ConvertingCAD();
string sourceFilePath = MyDir + "conic_pyramid.dxf";
using (Aspose.CAD.Image image = Aspose.CAD.Image.Load(sourceFilePath))
{
    // Create an instance of CadRasterizationOptions
    Aspose.CAD.ImageOptions.CadRasterizationOptions rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions();
    // Set page width & height
    rasterizationOptions.PageWidth = 1200;
    rasterizationOptions.PageHeight = 1200;

    // Create an instance of PngOptions for the resultant image
    ImageOptionsBase options = new Aspose.CAD.ImageOptions.PngOptions();
    // Set rasterization options
    options.VectorRasterizationOptions = rasterizationOptions;

    MyDir = MyDir + "conic_pyramid_raster_image_out.png";
    // Save resultant image
    image.Save(MyDir, options);                
}

将CAD布局转换为栅格图像格式

Aspose.CAD for .NET API能够将受支持格式(如DXF和DWG)的 CAD布局转换为光栅图像(如PNG,BMP,TIFF,JPEG和GIF)。该API还提供了将CAD图形的特定布局呈现到不同PSD层的支持。

Aspose.CAD for .NET API已公开了有效且易于使用的方法,用于指定所需CAD布局的列表并将其呈现为光栅图像格式。您可以通过以下5个简单的步骤来实现相同的目标。

  1. 使用工厂方法Load将CAD文件加载到Image实例中。
  2. 创建一个CadRasterizationOptions实例,并设置其必填属性,例如PageWidth和PageHeight。
  3. 使用CadRasterizationOptions.Layouts属性指定所需的布局名称。
  4. 创建ImageOptionsBase的实例并将其VectorRasterizationOptions属性设置为在上一步中创建的CadRasterizationOptions实例。
  5. 呼叫Image.Save通过将文件路径(或的MemoryStream的对象)以及实例ImageOptionsBase在先前步骤中创建的。
// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_ConvertingCAD();
string sourceFilePath = MyDir + "conic_pyramid.dxf";
using (Aspose.CAD.Image image = Aspose.CAD.Image.Load(sourceFilePath))
{
    // Create an instance of CadRasterizationOptions
    Aspose.CAD.ImageOptions.CadRasterizationOptions rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions();

    // Set page width & height
    rasterizationOptions.PageWidth = 1200;
    rasterizationOptions.PageHeight = 1200;

    // Specify a list of layout names
    rasterizationOptions.Layouts = new string[] { "Model", "Layout1" };

    // Create an instance of TiffOptions for the resultant image
    ImageOptionsBase options = new Aspose.CAD.ImageOptions.TiffOptions(Aspose.CAD.FileFormats.Tiff.Enums.TiffExpectedFormat.Default);

    // Set rasterization options
    options.VectorRasterizationOptions = rasterizationOptions;

    MyDir = MyDir + "conic_pyramid_layoutstorasterimage_out.tiff";

    // Save resultant image
    image.Save(MyDir, options);                
}

如果您有任何疑问或需求,请随时加入Aspose技术交流群(642018183),我们很高兴为您提供查询和咨询。

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表