[]
Skia is an open source 2D graphics library that provides common APIs that work as the graphics engine for Google Chrome and Chrome OS, Android, Flutter, Mozilla Firefox, Firefox OS, and many other products. In addition to this, SkiaSharp is a comprehensive cross-platform 2D graphics API for .NET platform used across mobile, server and desktop models to render images.
The Skia library, just like DsImaging, offers a rendering engine for drawing text and graphics. However, in case of Skia, the rendering engine is based on SkiaSharp and has dependency on SkiaSharp and SkiaSharp.NativeAssets.Linux nuget packages. The Skia library uses the exactly same implementation to render text and graphics as that of GcGraphics library. The difference is that the Skia library uses Skia engine at backend. In other words, you can use same approach to draw text and graphics while using the two libraries. However, both of them have their own merits and any of them could be used depending on the requirement of your application. Below are few recommended scenarios for each of them.
You should use Skia when your application:
Requires rendering large or complex images.
Requires rendering text with fonts hinting and subpixel rendering
Does not require access to individual pixels, DPI other than 96, EXIF/ICC profiles support, or effects such as dithering.
Can afford to have two heavy nuget packages of SkiaSharp and SkiaSharp.NativeAssets.Linux.
You should use DsImaging when your application:
Requires advanced drawing features such as transparency marks or logical operations on clip regions that are available via BitmapRenderer.
Needs large fonts for creating images such as CJK.
Requires pixel level access.
Processes large images but has limited physical memory size.
Requires small footprint.
For detailed information regarding the structure of these two libraries, see DsImaging and Skia in product architecture.
The code below shows how to render text and graphics using Skia library:
// GcSkiaGraphics calls CreateTextLayout method to render text
using var g = new GcSkiaGraphics(800, 600, false, Color.White);
g.DrawRoundRect(new RectangleF(5, 5, 790, 590), 20, Color.Blue, 2, DashStyle.DashDot);
float DegToRad = (float)Math.PI / 180;
g.Transform = Matrix3x2.CreateRotation(30 * DegToRad) * Matrix3x2.CreateTranslation(100, 50);
var tl = g.CreateTextLayout();
tl.Append("Hello World!", new TextFormat()
{
FontName = "Segoe UI",
ForeColor = Color.SandyBrown,
FontSize = 50f
});
g.DrawTextLayout(tl, PointF.Empty);
using var skiaImage = g.ToSkiaImage();
skiaImage.SaveAsPng("result_text.png");
// GcSkiaBitmap calls CreateGraphics method to render graphics
using var bmp = new GcSkiaBitmap(800, 600, false);
using (var h = bmp.CreateGraphics(Color.White))
{
h.Transform = Matrix3x2.CreateRotation(-30 * DegToRad) * Matrix3x2.CreateTranslation(400, 400);
var rect = new RectangleF(0, 0, 300, 200);
h.FillEllipse(rect, new HatchBrush(HatchStyle.Backslashes) { ForeColor = Color.MediumPurple });
h.DrawEllipse(rect, new Pen(Color.Red, 3));
}
bmp.SaveAsPng("result_graphics.png");
Limitation
The Skia library has dependency on SkiaSharp and SkiaSharp.NativeAssets.Linux packages.
Skia does not support changing image resolution, hence all the images are loaded and saved at 96 dpi only. However, you can implement a partial workaround by using scaling transformation.
GcSkiaGraphics does not support hardware acceleration and transparency group feature.
GcSkiaGraphics does not support the "Transparency Groups" feature required for drawing some PDF files to images. However, you can use GcBitmapGraphics or GcD2DBitmapGraphics classes to work around the same.