Convert EMF+ (not WMF / EMF) file to PNG in java

匿名 (未验证) 提交于 2019-12-03 09:02:45

问题:

Problem:

I have a an image of Enhanced Metafile Fromat Plus Extension EMF+. I need to convert this file to to a PNG image file with java.

Attempts to resolve problem in java:

  1. Apache Batik does not support EMF+ format (Batik supports WMF only format).

  2. FreeHEP does not support EMF+ too. It can convert EMF to SVG and then SVG to PNG. I hoped it can help:

    EMF2SVG.main( new String[] {inputMetaFileName,ontputSvgFileName}); 

    this statement must convert EMF to SVG, but gives an exception:

    java.lang.NullPointerException at org.freehep.graphicsio.exportchooser.AbstractExportFileType.getGraphics(AbstractExportFileType.java:261) at org.freehep.graphicsio.exportchooser.AbstractExportFileType.exportToFile(AbstractExportFileType.java:248) at org.freehep.graphicsio.exportchooser.AbstractExportFileType.exportToFile(AbstractExportFileType.java:282) at org.freehep.graphicsio.emf.EMFConverter.export(EMFConverter.java:81) at org.freehep.graphicsio.emf.EMF2SVG.main(EMF2SVG.java:27)

  3. I used code from here:

    try {     // read the EMF file     EMFRenderer emfRenderer = new EMFRenderer( new EMFInputStream(         new ByteArrayInputStream(emfBytes)));      EMFPanel emfPanel = new EMFPanel();     emfPanel.setRenderer(emfRenderer);      // prepare Graphics2D     FileOutputStream svg = new FileOutputStream("svg.svg");     SVGGraphics2D graphics2D = new SVGGraphics2D (svg, emfPanel);      // export to SVG     graphics2D.startExport();     emfPanel.print(graphics2D);     graphics2D.endExport();     svg.flush();     svg.close(); } catch (IOException e) {     e.printStackTrace(); } 

    This code creates SVG file, but it file has no image.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!