Regolazione della dimensione del disegno CAD

Regolazione della dimensione del disegno CAD

Aspose.CAD per Java fornisce l’enumerazione UnitType per regolare la dimensione del disegno durante la conversione del formato CAD. Ci sono due modi per regolare la dimensione del disegno.

  1. Regolazione automatica della dimensione
  2. Regolazione della dimensione utilizzando l’enumerazione UnitType della classe com.aspose.cad.imageoptions

Per la regolazione automatica della dimensione, gli sviluppatori non devono fornire le proprietà Larghezza e Altezza della classe CadRasterizationOptions. Di seguito è fornito un esempio di codice per la dimensione automatica.

// 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);

L’enumerazione UnitType offre la possibilità di regolare la scala quando le proprietà Larghezza e Altezza non sono impostate. Di seguito è fornito un esempio di codice che dimostra come utilizzare 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);