Aspose imaging throws exception when watermarking EMF/WMF files

Hi Team,

We are getting an exception using Aspose.Imaging 21.2.0 for .NET when trying to apply watermarking on EMF and WMF files.
The exception occurs both on linux and windows platforms.

The code snippet that is being used is copied from here:

Please find an example solution attached for reproducing the issue.
WatermarkVectorImage.zip (6.6 MB)

Can you please investigate the the issue! Thanks!

Zoltan

@zpopswat

Can you please share the stack trace with us. Please also try using latest Aspose.Imaging for .NET 21.4 as well on your end.

@mudassir.fayyaz
Pls find the stak trace below:

  • for EMF
    System.ArgumentNullException: Value cannot be null. (Parameter ‘image’)
    at …ctor(RasterImage , ICollection`1 )
    at Aspose.Imaging.Graphics.( )
    at Aspose.Imaging.Graphics.( )
    at Aspose.Imaging.Graphics.(String , Font , Brush , RectangleF, StringFormat , Boolean )
    at Aspose.Imaging.Graphics.DrawString(String s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format)
    at Aspose.Imaging.Graphics.DrawString(String s, Font font, Brush brush, Single x, Single y, StringFormat format)
    at WatermarkVectorImage.Program.watermarkEmfImageByAspose() in Program.cs:line 55

  • for WMF
    System.ArgumentNullException: Value cannot be null. (Parameter ‘image’)
    at …ctor(RasterImage , ICollection`1 )
    at Aspose.Imaging.Graphics.( )
    at Aspose.Imaging.Graphics.( )
    at Aspose.Imaging.Graphics.(String , Font , Brush , RectangleF, StringFormat , Boolean )
    at Aspose.Imaging.Graphics.DrawString(String s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format)
    at Aspose.Imaging.Graphics.DrawString(String s, Font font, Brush brush, Single x, Single y, StringFormat format)
    at WatermarkVectorImage.Program.watermarkWmfImageByAspose() in Program.cs:line 91

@mudassir.fayyaz

I’ve tried with the latest Aspose.Imaging for .NET 21.4 and I receive the same exceptions

@zpopswat

I have created a ticket with ID IMAGINGNET-4474 in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be fixed.

1 Like

@zpopswat

Currently EMF and WMF images work with graphics using their own Graphics classes. I have shared the example how to convert provided files.

        using (var image = Aspose.Imaging.Image.Load("chart.emf"))
        {
            EmfRecorderGraphics2D emfGraphics = EmfRecorderGraphics2D.FromEmfImage((EmfImage)image);

            // create an instance of Font. Initialize it with Font Face, Size and Style
            var font = new Aspose.Imaging.Font("Arial", 20, Aspose.Imaging.FontStyle.Bold);

            emfGraphics.DrawString("CONFIDENTIAL", font, Color.Red, 100, 100);
            EmfImage im2 = emfGraphics.EndRecording();
            im2.Save("output.emf");
        }

        using (var image = Aspose.Imaging.Image.Load("lantern.wmf"))
        {
            WmfRecorderGraphics2D emfGraphics = WmfRecorderGraphics2D.FromWmfImage((WmfImage)image);

            // create an instance of Font. Initialize it with Font Face, Size and Style
            var font = new Aspose.Imaging.Font("Arial", 20, Aspose.Imaging.FontStyle.Bold);

            emfGraphics.DrawString("CONFIDENTIAL", font, Color.Red, 100, 100);
            WmfImage im2 = emfGraphics.EndRecording();
            im2.Save("output.wmf");
        }
1 Like