Anpassen der Größe einer CAD-Zeichnung

Anpassen der Größe einer CAD-Zeichnung

Aspose.CAD für Java bietet die UnitType-Enumeration, um die Größe der Zeichnung während der Konvertierung des CAD-Formats anzupassen. Es gibt zwei Möglichkeiten, die Größe der Zeichnung anzupassen.

  1. Automatische Größenanpassung
  2. Größe anpassen, indem das UnitType-Enum der Klasse com.aspose.cad.imageoptions verwendet wird

Für die automatische Anpassung der Größe müssen Entwickler die Eigenschaften Width und Height der Klasse CadRasterizationOptions nicht angeben. Der untenstehende Code-Schnipsel ist ein Beispiel für automatische Größenanpassung.

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

Das UnitType-Enum bietet die Möglichkeit, die Skalierung anzupassen, wenn die Eigenschaften Width und Height nicht festgelegt sind. Der untenstehende Code-Schnipsel zeigt, wie man UnitType verwendet.

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