public static void main(String[] args) {
String dataDirBase ="D:\\wss_2021Q2\\Aspose.CAD-for-Java-master (1)\\Aspose.CAD-for-Java-master\\Examples\\src\\main\\resources\\";
String dataDir = dataDirBase + "CADConversion/";
String srcFile = dataDir+"五层平面图-.dwg";
long startTime = System.currentTimeMillis();
Image image = Image.load(srcFile);
int unitType = image.getUnitType();
int width = image.getWidth();
int height = image.getHeight();
//100万像素等比倍数
int zoom = 1008000 / width / height;
// Cad栅格化选项设置
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
// Set page width & height
if (zoom == 0) {
rasterizationOptions.setPageWidth(1920);
rasterizationOptions.setPageHeight(1080);
} else {
rasterizationOptions.setPageWidth(1200);
rasterizationOptions.setPageHeight(1200);
}
rasterizationOptions.setDrawType(CadDrawTypeMode.UseObjectColor);
rasterizationOptions.setUnitType(UnitType.Unitless);
//设置自动布局缩放
rasterizationOptions.setAutomaticLayoutsScaling(true);
// Create an instance of PngOptions for the resultant image
ImageOptionsBase pngOptions = new PngOptions();
//Set rasterization options
pngOptions.setVectorRasterizationOptions(rasterizationOptions);
//bmp图片
BmpOptions bmpOptions = new BmpOptions();
bmpOptions.setVectorRasterizationOptions(rasterizationOptions);
long endTime1 = System.currentTimeMillis();
System.out.println("图片转换配置时长为:"+(endTime1-startTime)+"ms");
image.save(dataDir + "1.bmp", bmpOptions);
long endTime2 = System.currentTimeMillis();
System.out.println("图片转换bmp时长为:"+(endTime2-endTime1)+"ms");
// Save resultant image
image.save(dataDir + "2.png", pngOptions);
long endTime3 = System.currentTimeMillis();
System.out.println("图片转换png时长为:"+(endTime3-endTime2)+"ms");
//ExEnd:ConvertCADDrawingToRasterImageFormat
}