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:
You should use DsImaging when your application:
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:
C# |
Copy Code
|
---|---|
// 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