PNG图片转EMF格式

public static String pngToEmf(String filePath, String outPath)
    {
        String result = null;
        // 保存svg到本地文件
        try (FileOutputStream outputStream = new FileOutputStream(new File(outPath))) {

            BufferedImage image = ImageIO.read(new File(filePath));
            int width = image.getWidth();
            int height = image.getHeight();
            VectorGraphics g = new EMFGraphics2D(new File(outPath), new Dimension(width, height));
            g.startExport();
            g.drawImage(image, 0, 0, width, height, null);
            g.endExport();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        } catch (IOException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }

        return result;
    }
		<dependency>
            <groupId>org.apache.xmlgraphics</groupId>
            <artifactId>batik-all</artifactId>
            <version>1.17</version>
        </dependency>
        <dependency>
            <groupId>org.apache.xmlgraphics</groupId>
            <artifactId>fop</artifactId>
            <version>2.6</version>
        </dependency>
        <dependency>
            <groupId>org.apache.xmlgraphics</groupId>
            <artifactId>xmlgraphics-commons</artifactId>
            <version>2.6</version>
        </dependency>
        <dependency>
            <groupId>org.apache.pdfbox</groupId>
            <artifactId>pdfbox</artifactId>
            <version>2.0.24</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.freehep/freehep-graphicsio -->
        <dependency>
            <groupId>org.freehep</groupId>
            <artifactId>freehep-graphicsio</artifactId>
            <version>2.1.3</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.freehep/freehep-graphicsio-java -->
        <dependency>
            <groupId>org.freehep</groupId>
            <artifactId>freehep-graphicsio-java</artifactId>
            <version>2.1.3</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.freehep/freehep-graphicsio-emf -->
        <dependency>
            <groupId>org.freehep</groupId>
            <artifactId>freehep-graphicsio-emf</artifactId>
            <version>2.1.3</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.freehep/freehep-graphics2d -->
        <dependency>
            <groupId>org.freehep</groupId>
            <artifactId>freehep-graphics2d</artifactId>
            <version>2.1.3</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.freehep/freehep-graphicsio-svg -->
        <dependency>
            <groupId>org.freehep</groupId>
            <artifactId>freehep-graphicsio-svg</artifactId>
            <version>2.1.3</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.freehep/freehep-io -->
        <dependency>
            <groupId>org.freehep</groupId>
            <artifactId>freehep-io</artifactId>
            <version>2.2.1</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.birt.runtime</groupId>
            <artifactId>org.w3c.css.sac</artifactId>
            <version>1.3.1.v200903091627</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.w3c.dom/org.w3c.dom.svg -->
        <dependency>
            <groupId>org.w3c.dom</groupId>
            <artifactId>org.w3c.dom.svg</artifactId>
            <version>1.1.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.w3c.dom/org.w3c.dom.smil -->
        <dependency>
            <groupId>org.w3c.dom</groupId>
            <artifactId>org.w3c.dom.smil</artifactId>
            <version>1.0.1.v200903091627</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.xmlgraphics/xmlgraphics-commons -->
        <dependency>
            <groupId>org.apache.xmlgraphics</groupId>
            <artifactId>xmlgraphics-commons</artifactId>
            <version>1.5</version>
        </dependency>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值