Adjusting CAD Drawing Size
Adjusting CAD drawing size
Aspose.CAD for Java provides the UnitType enumeration to adjust the size of the drawing during the conversion of the CAD format. There are two ways to adjust the drawing size.
- Automatic adjust size
- Adjust size by using the UnitType enumeration of the com.aspose.cad.imageoptions class
For automatic adjusting the size, developers do not need to provide the Width and Height properties of the CadRasterizationOptions class. Below provided code snippet is an example of automatic sizing.
// 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 enumeration gives the ability to adjust scaling when Width and Height properties are not set. Below provided code snippet demonstrate how to use UnitType.
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); |