调整 CAD 图纸大小
Contents
[
Hide
]使用 Aspose.CAD for Java,开发人员可以在转换 CAD 格式时调整图纸的大小。本主题解释了使用 UnitType 枚举的自动调整或手动调整大小的方法,属于 com.aspose.cad.imageoptions 类。
调整 CAD 图纸大小
Aspose.CAD for Java 提供 UnitType 枚举以在转换 CAD 格式时调整图纸的大小。有两种方法可以调整图纸大小。
- 自动调整大小
- 使用 UnitType 枚举调整大小,属于 com.aspose.cad.imageoptions 类
对于自动调整大小,开发人员不需要提供 CadRasterizationOptions 类的宽度和高度属性。下面提供的代码片段是自动调整大小的示例。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java | |
// Path to source file | |
String sourceFilePath = "sample.dwg"; | |
// Load a CAD drawing in an instance of Image | |
com.aspose.cad.Image objImage = com.aspose.cad.Image.load("sourceFilePath"); | |
// Create an instance of BmpOptions class | |
com.aspose.cad.imageoptions.BmpOptions bmpOptions = new com.aspose.cad.imageoptions.BmpOptions(); | |
// Create an instance of CadRasterizationOptions and set its various properties | |
com.aspose.cad.imageoptions.CadRasterizationOptions cadRasterizationOptions = | |
new com.aspose.cad.imageoptions.CadRasterizationOptions(); | |
bmpOptions.setVectorRasterizationOptions(cadRasterizationOptions); | |
cadRasterizationOptions.setCenterDrawing(true); | |
// Set the layouts property | |
cadRasterizationOptions.setLayouts( new String[] { "Model" } ); | |
// Export layout to BMP format | |
String outPath = sourceFilePath + ".bmp"; | |
objImage.save(outPath, bmpOptions); |
UnitType 枚举提供了在未设置宽度和高度属性时调整缩放的能力。下面提供的代码片段演示了如何使用 UnitType。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getDataDir(AdjustingCADDrawingSizeUsingUnitType.class) + "CADConversion/"; | |
// Path to source file | |
String sourceFilePath = dataDir + "sample.dwg"; | |
// Load a CAD drawing in an instance of Image | |
Image image = Image.load(sourceFilePath); | |
// Create an instance of BmpOptions class | |
com.aspose.cad.imageoptions.BmpOptions bmpOptions = new com.aspose.cad.imageoptions.BmpOptions(); | |
// Create an instance of CadRasterizationOptions and set its various properties | |
com.aspose.cad.imageoptions.CadRasterizationOptions cadRasterizationOptions = | |
new com.aspose.cad.imageoptions.CadRasterizationOptions(); | |
bmpOptions.setVectorRasterizationOptions(cadRasterizationOptions); | |
// Set the UnitType property | |
cadRasterizationOptions.setUnitType(com.aspose.cad.imageoptions.UnitType.Centimenter); | |
// Set the layouts property | |
cadRasterizationOptions.setLayouts( new String[] { "Model" } ); | |
// Export layout to BMP format | |
String outPath = sourceFilePath + ".bmp"; | |
image.save(outPath, bmpOptions); |