Closed
Description
Rendering a rotated bitmap with SKCanvas is slow, compared with System.Drawing (4x slower)
See below code, it produces following output:
rotation: 20°
Skia: 6860ms
System.Drawing: 1643ms
float rotation = 20;
Console.WriteLine("rotation: "+rotation+"°");
// Skia part...
MemoryStream imageStream = new MemoryStream(new WebClient().DownloadData(@"https://via.placeholder.com/450"));
SKBitmap skBitmapToBlit = SKBitmap.Decode(imageStream);
SKBitmap renderSkBitmap = new SKBitmap(512, 512, isOpaque: false);
SKCanvas canvas = new SKCanvas(renderSkBitmap);
SKPaint paint = new SKPaint()
{
FilterQuality = SKFilterQuality.High
};
canvas.RotateDegrees(rotation);
var sw = Stopwatch.StartNew();
for (int i=0; i<100; i++)
{
canvas.DrawBitmap(skBitmapToBlit, new SKPoint(10, 10), paint);
};
Console.WriteLine("Skia: "+sw.ElapsedMilliseconds + "ms");
// System.Drawing part...
imageStream = new MemoryStream(new WebClient().DownloadData(@"https://via.placeholder.com/450"));
Bitmap gdiBitmapToBlit = new Bitmap(imageStream);
Bitmap renderGdiBitmap = new Bitmap(512, 512, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
Graphics graphics = Graphics.FromImage(renderGdiBitmap);
graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Bicubic;
graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;
var matrix = new Matrix();
matrix.Rotate(rotation);
graphics.Transform=matrix;
sw = Stopwatch.StartNew();
for (int i = 0; i < 100; i++)
{
graphics.DrawImage(gdiBitmapToBlit, new PointF(10, 10));
};
Console.WriteLine("System.Drawing: " + sw.ElapsedMilliseconds + "ms");
Note that, without rotating, Skia is much faster than System.Drawing (36x faster).
Symptom : Skia 4x slower than System.Drawing, with provided code.
Expected : Skia faster than System.Drawing, with provided code.
- Version with issue: 1.68.0
- Last known good version: N/A
- IDE: Visual Studio
- Platform Target Frameworks: .net framework 4.7
VS bug #776803