Incorrectly display or save emf to other image format, in Aspose-Imaging, all versions since 20.2

Hi,

Happy new year.

We upgraded aspose imaging java from com.aspose:aspose-imaging:19.10:jdk16 to com.aspose:aspose-imaging:22.12:jdk16 recently, and found that some emf files can’t be displayed because the api EmfMetafileImage.playMetafile(Graphics2D) was removed since version 20.2

Then we tried to find the alternative of it, and the code below works in most cases.
BufferedImage image = ImageExtensions.toJava(emf);
graphics2D.drawImage(image , 0, 0, (int) emf.getWidth(), (int) emf.getHeight(), null);

However, some of emf can’t be displayed correctly, and it seems that the entire frame will be moved to right and bottom by roughly 100 pixels.
To investigate that issue, we tried to save the emf to other formats like wmf, png and svg. And they are all the same and the frame is always moved. The sample code and sample test data are below.

import java.io.File;

import com.aspose.imaging.Image;
import com.aspose.imaging.ImageOptionsBase;
import com.aspose.imaging.fileformats.emf.EmfImage;
import com.aspose.imaging.fileformats.emf.EmfRenderMode;
import com.aspose.imaging.imageoptions.EmfRasterizationOptions;
import com.aspose.imaging.imageoptions.PngOptions;

public class TestEmf {
    public static void main(String[] args) throws Exception {
        File emfFile = new File("src/main/resources/emf/test.emf");
        File outputFile = new File("src/main/resources/emf/out-test.png");

        //We try to display this emf file or save it to another image file.
        // the api playMetafile in the old class EmfMetafileImage works, but it is in aspose imaging 19.x only and has been removed since aspose imaging 20.2
//        EmfMetafileImage emfMetafileImage = new EmfMetafileImage(emfFile.getAbsolutePath());
//        emfMetafileImage.playMetafile(Graphics2D);

        //The code below is mostly same to https://reference.aspose.com/imaging/java/com.aspose.imaging.imageoptions/emfrasterizationoptions/
        //It can create the Png file successfully.
        //However, the frame is moved, and roughly 100 pixels in right and bottom are missing.
        //It is the same if we save the emf to wmf, png or svg, the 100 pixels (roughly) in right and bottom are always missing.
        EmfImage emfImage = (EmfImage) Image.load(emfFile.getAbsolutePath());
        try {
            ImageOptionsBase saveOptions = new PngOptions();
            EmfRasterizationOptions rasterizationOptions = new EmfRasterizationOptions();
            rasterizationOptions.setPageWidth(emfImage.getWidth());
            rasterizationOptions.setPageHeight(emfImage.getHeight());
            rasterizationOptions.setRenderMode(EmfRenderMode.Auto);
            saveOptions.setVectorRasterizationOptions(rasterizationOptions);

            emfImage.save(outputFile.getAbsolutePath(), saveOptions);
        } finally {
            emfImage.dispose();
        }
    }
}

Test data:
emf-test-data.zip (28.3 KB)

My questions are

  1. could class EmfMetafileImage and method emfMetafileImage.playMetafile(Graphics2D) be added back in the future, or could you tell us where they are in versions after 20.2?
  2. if the answer to 1 is No, could you tell us how to render the sample emf file successfully? Thanks.

Regards,
Tony

@Tony_Li Happy new year! We are going to test your Emf file, investigate this issue and you will be notified shortly.

Hi @Alexey.Karpenko any update on this? Thanks :slight_smile:
Can you reproduce the issue? I’m happy to send more test data if you want.

@Tony_Li The issue is reproduced and it also applies to .Net Framework version.

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): IMAGINGNET-6096

You can obtain Paid Support services if you need support on a priority basis, along with the direct access to our Paid Support management team.

Thanks. Good to hear that it is under tracking now.

Hi @Alexey.Karpenko, May I ask if there is any update on this? Thanks.

@Tony_Li The fix for this issue is almost finished, but still in progress. It will be released as soon as possible.

The issues you have found earlier (filed as IMAGINGNET-6096) have been fixed in this update. This message was posted using Bugs notification tool by samer.el-khatib