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();
}
}
}
}
}
}
}
}