We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

EMF Images transformed to PNG are not shown in Azure Environment using Aspose.Slides for .NET

We are evaluating the product for a customer and we need to figure this issue before to recommend the product.

As we saw that EMF images are not being draw in Azure, we are converting them to PNG, but converted images are not being shown as well.

In a local Desktop environment images are being shown.

Here is the code:
we store the pictureFrames that contains EMF images and then we transform the image and we add a new PictureFrame and remove the old one.

            foreach (var pf in PictureFrameList)
                IPPImage oldImage = pf.PictureFormat.Picture.Image;
                Image newImage = Image.FromStream(ReplaceImage(oldImage));
                IPPImage newImagetoAdd = presentation.Images.AddImage(newImage);

                // Add Picture Frame with height and width equivalent of Picture
                IPictureFrame picframe = slide.Shapes.AddPictureFrame(ShapeType.Rectangle, pf.X, 
                    pf.Y, pf.Width, pf.Height, newImagetoAdd);
                picframe.LineFormat.FillFormat.FillType = FillType.Solid;
                picframe.LineFormat.FillFormat.SolidFillColor.Color = Color.Red;
                picframe.LineFormat.Width = 2;

/* this is the code that replaces the image*/

    public MemoryStream ReplaceImage(IPPImage pic)

        byte[] bytes = pic.BinaryData;
        Stream oldPicStream = new MemoryStream(bytes);
        MemoryStream NewPictureStream = new MemoryStream();

        ConvertMetafile(oldPicStream, NewPictureStream, 0, Color.Transparent, ImageFormat.Png,null);
        Image newImage = Image.FromStream (NewPictureStream);
        newImage.Save(NewPictureStream, ImageFormat.Png);

        return NewPictureStream;


*/ THIS IS THE CODE OF ConvertMetafile */

    public void ConvertMetafile(Stream source, Stream destination, float scale, Color? backgroundColor, ImageFormat format, EncoderParameters parameters)
        scale = 4f;
        backgroundColor = null;
        format = null;
        parameters = null;

        if (source == null)
            throw new ArgumentNullException(nameof(source));
        if (destination == null)
            throw new ArgumentNullException(nameof(destination));

        using (var img = new Metafile(source))
            var f = format ?? ImageFormat.Png;

            //Determine default background color. 
            //Not all formats support transparency. 
            if (backgroundColor == null)
                var transparentFormats = new ImageFormat[] { ImageFormat.Gif, ImageFormat.Png, ImageFormat.Wmf, ImageFormat.Emf };
                var isTransparentFormat = transparentFormats.Contains(f);

                backgroundColor = isTransparentFormat ? Color.Transparent : Color.White;

            //header contains DPI information
            var header = img.GetMetafileHeader();

            //calculate the width and height based on the scale
            //and the respective DPI
            var width = (int)Math.Round((scale * img.Width / header.DpiX * 100), 0, MidpointRounding.ToEven);
            var height = (int)Math.Round((scale * img.Height / header.DpiY * 100), 0, MidpointRounding.ToEven);

            using (var bitmap = new Bitmap(width, height))
                using (var g = System.Drawing.Graphics.FromImage(bitmap))
                    //fills the background

                    //reuse the width and height to draw the image
                    //in 100% of the square of the bitmap
                    g.DrawImage(img, 0, 0, bitmap.Width, bitmap.Height);

                //get codec based on GUID
                var codec = ImageCodecInfo.GetImageEncoders().FirstOrDefault(c => c.FormatID == f.Guid);

                bitmap.Save(destination, codec, parameters);



I have observed the information shared by you and request you to please provide the information that if when converting EMF to PNG you can save PNG on disk and confirm if file has been properly converted. Please share the source project and sample images if you are able to observe the images saved on disks. Please also provide the environment details on your end as well.

hi @mudassir.fayyaz,

Thank you for your quick response, I’m able to save transformed images to disk, testing on a local environment.
I’m attaching the project a sample pptx that contains the images and the images converted.

The environment in which we need to have it transforming images is an azure function, in a local environment it shows the converted images in a correct way.



I have observed your comments. I am unable to observe any attachment to this thread. Can you please attach files again and inform us here.

@Adnan.Ahmad now?, I’m trying to attach it, is there a restiction?

ForAspose.zip (67.4 KB)
@Adnan.Ahmad here it is



I have worked with the presentation file shared by you and have been able to observe the issue specified. An issue with ID SLIDESNET-40758 has been created in our issue tracking system to 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.

thank you @Adnan.Ahmad