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>