Inconsistent Dimensions of WMF Image Reported by Various Interfaces

Hi Team,

I am handling various image types embedded into Powerpoint files. For my code to function properly I need to know the exact dimensions of the embdedded image.
For that purpose I seem to have a multitude of Aspose APIs at my disposal to determine the image dimensions, however these APIs report inconsistent numbers for wmf vector images.

The APIs in question are:

  • Aspose.Slides.IPPImage.Height / Aspose.Slides.IPPImage.Width
  • Aspose.Slides.IPPImage.SystemImage.Height / Aspose.Slides.IPPImage.SystemImageWidth
  • Aspose.Imaging.Image.Height / Aspose.Imaging.Image.Height

All three seem to report the same dimensions for e.g: jpeg and emf files however for wmf files
the former two seem to report the same dimensions but Aspose.Imaging API report completely different numbers.

Can you please help me clarify this?

I’ve tried it on windows platform with Aspose.Imaging 21.11 and Aspose.Slides 21.11

I have implemented an example solution to demonstrate this.
Please find it attached.

Thanks, Zoltan
VectorImageSizeInconsistencyInSlides.zip (401.2 KB)

However what I have noticed is that for wmf

@zpopswat,
Thank you for contacting support. We will reply to you as soon as possible.

@zpopswat,
Thank you for your patience. Please share the following:

  • output of console after running this code
  • OS version on which the code was running

@Andrey_Potapov: pls. find the requested info below

Windows Server 2019 Standard, .NET Core SDK (3.1.301)

Image detected on slide[1]. Image type [Wmf] Height[11659] Width[9846]
IPPImage size Height[11659] Width[9846]
IPPImage.SystemImage size Height[11659] Width[9846]
MetaImage size Height[1119] Width[945] type[Wmf]
Image detected on slide[2]. Image type [Emf] Height[7511] Width[15024]
IPPImage size Height[7511] Width[15024]
IPPImage.SystemImage size Height[7512] Width[15025]
MetaImage size Height[7512] Width[15025] type[Emf]
Image detected on slide[3]. Image type [Jpeg] Height[450] Width[450]
IPPImage size Height[450] Width[450]
IPPImage.SystemImage size Height[450] Width[450]
RasterRaster size Height[450] Width[450] type[Jpeg]

Linux Mint 20 Ulyana, dotnet version 3.1.414

Image detected on slide[1]. Image type [Wmf] Height[11659] Width[9846]
IPPImage size Height[11659] Width[9846]
IPPImage.SystemImage size Height[11659] Width[9846]
MetaImage size Height[1119] Width[945] type[Wmf]
Image detected on slide[2]. Image type [Emf] Height[7512] Width[15025]
IPPImage size Height[7512] Width[15025]
IPPImage.SystemImage size Height[7512] Width[15025]
MetaImage size Height[7512] Width[15025] type[Emf]
Image detected on slide[3]. Image type [Jpeg] Height[450] Width[450]
IPPImage size Height[450] Width[450]
IPPImage.SystemImage size Height[450] Width[450]
RasterRaster size Height[450] Width[450] type[Jpeg]

@zpopswat,
Thank you for the additional information. I have reproduced the problem with the image dimensions and added a ticket with ID SLIDESNET-42943 in our issue tracking system. Our development team will investigate this case. You will be notified when the issue is resolved.

1 Like

@zpopswat,
Our development team investigated the issue. Aspose.Slides API in this part relies on the .NET System.Drawing.Imaging.Metafile implementation. So by using a raw .NET implementation result will be the same as via Slides API in this case:

System.Drawing.Imaging.Metafile metafile = new Metafile("image1.wmf");
Console.WriteLine($"\tSystem.Drawing.Imaging.Metafile size\tHeight[{metafile.Height}]\tWidth[{metafile.Width}]");

Output:
System.Drawing.Imaging.Metafile size Height[11659] Width[9846]

I have moved this forum thread to Aspose.Imaging forum. We suppose Aspose.Imaging.FileFormats.Emf.MetaImage class implementation should be tested.

Our support team will help you further.

1 Like

@Andrey_Potapov
We’ve reviewed the issue and found, that after saving to disk outputBin1.zip (189.2 KB)
of the slide with wmf file using following code snippet :

File.WriteAllBytes($"outputBin{slide.SlideNumber}.{ippimage.SystemImage.RawFormat}", ippimage.BinaryData);

we could find the same to Aspose.Imaging file size metrics using IrfanView.slide1WmfMetrics.png (176.7 KB)

In the same time saving to the disk using:

ippimage.SystemImage.Save($"output{slide.SlideNumber}.{ippimage.SystemImage.RawFormat}");

produces wrong results.

Please let us know if you need more help with that.

Thanks
@zpopswat
FYI

@aifeigin4aspose,
Thank you for the additional information.

Could you please share your results?

@Andrey_Potapov
output1.zip (75.0 KB)

@aifeigin4aspose,
Thank you. I have passed your information to Aspose.Slides team.

@andrey.potapov
This issue seems to persist with with Aspose.Imaging 24.2.0 and Aspose.Slides 24.1.0

MetaImage.Height and MetaImage.Width properties still return incorrect values for wmf files in slide files (see last line below).

Image detected on slide[1]. Image type [Wmf]  Height[11659]  Width[9846]
        IPPImage size  Height[11659]  Width[9846]
        IPPImage.SystemImage size  Height[11659]  Width[9846]
        MetaImage size  Height[1119]  Width[945]   type[Wmf]

Can you please give me an estimate of when this will be fixed? Thank you

@zpopswat,
I am working on the question and will get back to you soon.

@zpopswat,
Thank you for your patience. Our developers have investigated the case. To get the same result in Aspose.Imaging, you can use the WmfImage.FrameBounds property. The following code example shows you how to do this:

using (var presentation = new Presentation("emf_wmf_jpg.pptx"))
{
    foreach (var slide in presentation.Slides)
    {
        foreach (var shape in slide.Shapes)
        {
            if (shape is PictureFrame pictureFrame && null != pictureFrame.PictureFormat.Picture.Image)
            {
                IPPImage ippimage = pictureFrame.PictureFormat.Picture.Image;
                Console.WriteLine(
                    $"Image detected on slide[{slide.SlideNumber}]. Image type {ippimage.SystemImage.RawFormat}");
                Console.WriteLine(
                    $"\tIPPImage size\t\t\tHeight[{ippimage.Height}]\tWidth[{ippimage.Width}]");
                Console.WriteLine(
                    $"\tIPPImage.SystemImage size\tHeight[{ippimage.SystemImage.Height}]\tWidth[{ippimage.SystemImage.Width}]");

                var imageStream = new MemoryStream(ippimage.BinaryData);
                using (Image image = Image.Load(imageStream))
                {
                    if (image is RasterImage rasterImage)
                    {
                        Console.WriteLine(
                            $"\tRasterImage size\t\tHeight[{rasterImage.Height}]\tWidth[{rasterImage.Width}]\ttype[{rasterImage.FileFormat}]");
                        if (!rasterImage.IsCached)
                        {
                            rasterImage.CacheData();
                        }
                    }
                    else if (image is MetaImage metaImage)
                    {
                        if (image is WmfImage wmfImage)
                        {
                            Console.WriteLine(
                                $"\tWmfImage size\t\tHeight[{wmfImage.FrameBounds.Height}]\tWidth[{wmfImage.FrameBounds.Width}]\ttype[{metaImage.FileFormat}]");
                        }
                        else
                        {
                            Console.WriteLine(
                                $"\tMetaImage size\t\t\tHeight[{metaImage.Height}]\tWidth[{metaImage.Width}]\ttype[{metaImage.FileFormat}]");
                        }

                        if (!metaImage.IsCached)
                        {
                            metaImage.CacheData();
                        }
                    }
                }
            }
            Console.WriteLine();
        }
    }
}