编程语言
首页 > 编程语言> > 通过java把cad的dwg文件转换为svg文件

通过java把cad的dwg文件转换为svg文件

作者:互联网

本方法是通过引入aspose-cad工具来把dwg转换为svg, aspose-cad的下载地址为: https://mvnrepository.com/artifact/com.aspose/aspose-cad, 我是通过本地测试来转换的, 可以成功转换
File file = new File("G:/cad");
    File[] files = file.listFiles();
    for (File file1 : files) {
        String path = file1.getAbsolutePath();
        String name = file1.getName().replace(".dwg", "");

        Image cadImage = Image.load(path);
        CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
        rasterizationOptions.setAutomaticLayoutsScaling(true);
        rasterizationOptions.setNoScaling (false);
        rasterizationOptions.setContentAsBitmap(true);
        rasterizationOptions.setLayouts(new String[] {"Model"});
        SvgOptions svgOptions = new SvgOptions();
                rasterizationOptions.getGraphicsOptions().setSmoothingMode(SmoothingMode.HighQu        ality);
              rasterizationOptions.getGraphicsOptions().setTextRenderingHint(TextRenderingHin        t.AntiAliasGridFit);
               rasterizationOptions.getGraphicsOptions().setInterpolationMode(InterpolationMod        e.HighQualityBicubic);


        int width = cadImage.getWidth();
        int height = cadImage.getHeight();
        float zoom = 2.5f;
        rasterizationOptions.setPageHeight(height * zoom);
        rasterizationOptions.setPageWidth(width * zoom);
        rasterizationOptions.setDrawType(CadDrawTypeMode.UseObjectColor);

        svgOptions.setVectorRasterizationOptions(rasterizationOptions);
        cadImage.save("G:/output/" + name +".svg", svgOptions);
    }

标签:文件,rasterizationOptions,svg,cadImage,dwg,File,aspose,new,cad
来源: https://blog.csdn.net/qq_41728752/article/details/122810033