Free Support Forum - aspose.com

Aspose.cad实现cad图片转换png、bmp,转换时间比较长,复杂图片出现内存溢出的问题,性能如何优化

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
    
    }

@wangqi123

您能否以源文件和最终发生的问题的快照的形式共享问题的详细信息。