/**
* emf转png
*
* @param emfPath emf地址
* @param pngPath png地址
*/
private static void emfToPng(String emfPath, String pngPath) throws IOException {
EMFInputStream inputStream = new EMFInputStream(new FileInputStream(emfPath), EMFInputStream.DEFAULT_VERSION);
EMFRenderer emfRenderer = new EMFRenderer(inputStream);
int width = (int) inputStream.readHeader().getBounds().getWidth();
int height = (int) inputStream.readHeader().getBounds().getHeight();
BufferedImage result = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = result.createGraphics();
//设置背景色
g2.setBackground(Color.WHITE);
//通过使用当前绘图表面的背景色进行填充来清除指定的矩形。
g2.clearRect(0, 0, width, height);
emfRenderer.paint(g2);
ImageIO.write(result, "png", new File(pngPath + File.separator + StringUtils.getRandomNumber() + ".png"));
g2.dispose();
}
在Linux环境会出现中文文字乱码情况,参考这篇文章,简单配置下即可;
Graphics2D画图,linux环境下中文乱码问题_Zeke_Red的博客-CSDN博客_graphics2d中文乱码