在 Java 中以编程方式将 DGN 转换为 JPG

在这一部分,我们将简要概述 Aspose.CAD for Java。此外,我们还将了解如何使用此 AutoCAD Java API 在 Java 中将 DGN 转换为 JPG

本节将带您安装此 Java

在这里,我们将通过编写一段代码来开发一个 DGN 文件转换器,该代码将使用 Aspose.CAD for Java 提供的方法和类。

同样,我们将查看一个由 Aspose.CAD for Java 提供支持的在线工具,用于将 DGN 文件格式转换为其他光栅图像。

几天前,我们发布了一些非常有用的 文章,强调了 Aspose.CAD for Java 提供的一些突出功能。在本指南中,我们将看到如何以编程方式将 DGN 文件格式导出为光栅图像文件。此外,我们将带您完成构建 DGN 到 JPG 转换器 所需的所有步骤。因此,如果您希望 在 Java 中将 DGN 转换为 JPG,本指南将是一个解决方案。最重要的是,此 AutoCAD Java API 在转换和操作过程中具有高度的安全性、健壮性和效率。

AutoCAD Java API 安装

请在 这里 下载 JAR 文件,或按照提到的 Maven 配置进行操作。

autocad java api 安装

DGN 到 JPG 转换器 - 代码示例

因此,您需要一个源 DGN 文件来实现此功能。现在,请按照以下步骤和代码片段进行操作:

public static void main(String[] args) throws FileNotFoundException
{
// Define the working directory.
String dataDir = "/Desktop/";
// Load an existing DGN file by invoking the load method.
DgnImage dgnImage = (DgnImage) Image.load(dataDir + "sample.dgn");
// Create an object of JpegOptions class as we are converting the DGN to JPG and assign DgnRasterizationOptions object to it.
ImageOptionsBase options = new JpegOptions();
// Instantiate an instance of the CadRasterizationOptions class.
CadRasterizationOptions vectorOptions = new CadRasterizationOptions();
// Set the width of the page by calling the setPageWidth method.
vectorOptions.setPageWidth(300);
// The setPageHeight method will set the page height.
vectorOptions.setPageHeight(200);
// Enable scaling during export by calling the setNoScaling method.
vectorOptions.setNoScaling(true);
// Set a value indicating whether layouts should be automatically scaled by calling the setAutomaticLayoutsScaling method.
vectorOptions.setAutomaticLayoutsScaling(false);
// The setVectorRasterizationOptions method will set the vector rasterization options.
options.setVectorRasterizationOptions(vectorOptions);
OutputStream outStream = new FileOutputStream(dataDir + "ExportDGNToRasterImage_Out.jpg");
// Call the save method of the CadImage class to save the JPG file on the disk.
dgnImage.save(outStream, options);
}
输出:

dgn 到 jpg 转换器

DGN 文件转换器 - 在线工具

此外,Aspose.CAD for Java 提供了一个企业级的 在线 工具,用于将 DGN 文件格式转换为其他光栅图像。最重要的是,这个 DGN 到 JPG 文件转换器 是免费的,您可以通过在拖放用户界面中拖放源文件来实现转换。

dgn 文件转换器

获取免费许可证

您可以获得一个免费的 临时许可证,以便在没有评估限制的情况下尝试此 AutoCAD Java API。

总结

这篇博客文章到此结束。希望您在开发 DGN 到 JPG 转换器方面找到了很大的帮助,因为我们已经实现了如何在 Java 中以编程方式将 DGN 转换为 JPG。此外,这个轻量级库还有很多其他功能,您可以通过访问 文档API 参考和 GitHub 仓库来了解更多内容。再次感谢您阅读这篇博客文章,我们将再次推出另一篇文章,因此请与 aspose.com 保持联系。

随时与我们联系

您可以在我们的 论坛 上告诉我们您的问题或疑问。

另请参见