Convert a wmf to gif

I'm trying to convert a wmf file to a png using SkiaSharp. I can successfully load the byte array into a new SKMemoryStream object, but creating the SKCodec object creates a null code object, and after that the SKMemoryStream object shows System.AccessViolationException errors. Can anyone assist?

using (SKMemoryStream sourceStream = new SKMemoryStream(imageData))
            {
                newExtension = ".png";

                using (SKCodec codec = SKCodec.Create(sourceStream))
                {
                    sourceStream.Seek(0);

                    using (SKImage image = SKImage.FromEncodedData(SKData.Create(sourceStream)))
                    {
                        using (SKSurface surface = SKSurface.Create(codec.Info.ColorSpace.IsSrgb ? new SKImageInfo(image.Width, image.Height) : new SKImageInfo(image.Width, image.Height, SKImageInfo.PlatformColorType, SKAlphaType.Premul, SKColorSpace.CreateSrgb())))
                        {
                            using (SKPaint paint = new SKPaint())
                            {
                                // High quality without antialiasing
                                paint.IsAntialias = true;
                                paint.FilterQuality = SKFilterQuality.High;

                                // Draw the bitmap to fill the surface
                                surface.Canvas.Clear(SKColors.White);
                                surface.Canvas.DrawImage(image, new SKRect(0, 0, image.Width, image.Height), paint);
                                surface.Canvas.Flush();

                                using (SKImage newImage = surface.Snapshot())
                                {
                                    using (SKData newImageData = newImage.Encode(SKEncodedImageFormat.Png, 100))
                                    {
                                        return newImageData.ToArray();
                                    }
                                }
                            }
                        }
                    }
                }
            }
Sign In or Register to comment.