CAD図面サイズの調整

CAD図面サイズの調整

Java用Aspose.CADは、CAD形式の変換中に図面のサイズを調整するためにUnitType 列挙型を提供します。図面サイズを調整する方法は2つあります。

  1. 自動サイズ調整
  2. com.aspose.cad.imageoptions クラスのUnitType 列挙型を使用してサイズを調整

サイズを自動調整する場合、開発者はCadRasterizationOptions クラスのWidthおよびHeightプロパティを提供する必要はありません。以下に自動サイズ調整の例を示すコードスニペットを提供します。

// 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 列挙型は、WidthおよびHeightプロパティが設定されていない場合にスケーリングを調整する機能を提供します。以下に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);