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

Problem:

I have an image of an extended Extat Plus EMF + metafile extension . I need to convert this file to a PNG image file using java.

Attempts to solve the problem in java:

  • Apache Batikdoes not support EMF + format (Batik only supports WMF format ).

  • FreeHEPdoes not support EMF + . It can convert EMF to SVG and then SVG to PNG . I was hoping this would help:

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

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

    java.lang. exportchooser.AbstractExportFileType.exportToFile (AbstractExportFileType.java:282) at org.freehep.graphicsio.emf.EMFConverter.export (EMFConverter.java:81) at org.freehep.graphicsio.emf.EMF2SVG.main (EMF2VV)

  • I used the code 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 an SVG file , but the file has no image.

+2
source share

Source: https://habr.com/ru/post/1656935/


All Articles