Re: SkiaSharp and wmf

306 views
Skip to first unread message

Brian Osman

unread,
Jul 20, 2018, 8:58:00 AM7/20/18
to skia-d...@googlegroups.com
Skia does support GIF (src/codec/SkGifCodec.cpp), so I think the problem is just that we don't support WMF. Unfortunately, I don't see any good solution - WMF support appears to be very difficult to find - even WIC doesn't support it.

On Fri, Jul 20, 2018 at 5:22 AM 'Amy Harris' via skia-discuss <skia-d...@googlegroups.com> wrote:
Hi

I'm trying to open a WMF file using SkiaSharp in order to save it as a png. It reads into the SKMemoryStream object with no issues, but when reading sourceStream into the SKCodec object, the SKCodec object is returned null. I know Skia doesn't handle WMFs but it also doesn't handle GIFs, and those files can be read by the SKCodec object with no errors. Can anyone assist?

private static byte[] ConvertObsoleteFileType(byte[] imageData, out string newExtension)
   
{
       
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();
                               
}
                           
}
                       
}
                   
}
               
}
           
}
       
}
   
}


--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To post to this group, send email to skia-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/skia-discuss.
For more options, visit https://groups.google.com/d/optout.

Matthew Leibowitz

unread,
Jul 20, 2018, 9:10:46 AM7/20/18
to skia-discuss
Skia supports READING .gif files.
Keep in mind that skia supports READING many raster formats, but can only WRITE to a few, such as .png, .webp, .jpeg
Reply all
Reply to author
Forward
0 new messages