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

2022/2/7 17:13:21

本文主要是介绍通过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);
    }


这篇关于通过java把cad的dwg文件转换为svg文件的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程