Cross-Platform .NET 6 Image Processing Libraries

Raymond Tang Raymond Tang 0 6948 5.51 index 1/15/2022

For .NET developers, one of the common used image processing library is the built in one Sytstem.Drawing. This library is based on GDI+ and only supports Windows OS. When compiling projects that reference this library, you may get the following warning messages:

Severity Code Description Project File Line Suppression State Warning CA1416 This call site is reachable on all platforms. 'Bitmap.SetPixel(int, int, Color)' is only supported on: 'windows'. Warning CA1416 This call site is reachable on all platforms. 'Bitmap' is only supported on: 'windows'. Warning CA1416 This call site is reachable on all platforms. 'Graphics.FromImage(Image)' is only supported on: 'windows'. Warning CA1416 This call site is reachable on all platforms. 'Graphics.FillRectangle(Brush, int, int, int, int)' is only supported on: 'windows'. Warning CA1416 This call site is reachable on all platforms. 'SolidBrush' is only supported on: 'windows'. Warning CA1416 This call site is reachable on all platforms. 'Pen' is only supported on: 'windows'. Warning CA1416 This call site is reachable on all platforms. 'Graphics.DrawLine(Pen, Point, Point)' is only supported on: 'windows'. Warning CA1416 This call site is reachable on all platforms. 'Font' is only supported on: 'windows'. Warning CA1416 This call site is reachable on all platforms. 'FontFamily.GenericMonospace' is only supported on: 'windows'. Warning CA1416 This call site is reachable on all platforms. 'FontStyle.Bold' is only supported on: 'windows'. Warning CA1416 This call site is reachable on all platforms. 'FontStyle.Italic' is only supported on: 'windows'. Warning CA1416 This call site is reachable on all platforms. 'GraphicsUnit.Pixel' is only supported on: 'windows'. Warning CA1416 This call site is reachable on all platforms. 'Graphics.DrawString(string?, Font, Brush, float, float)' is only supported on: 'windows'. Warning CA1416 This call site is reachable on all platforms. 'Image.Save(Stream, ImageFormat)' is only supported on: 'windows'. Warning CA1416 This call site is reachable on all platforms. 'ImageFormat.Png' is only supported on: 'windows'.

To remove these warning messages, we will have to use cross-platform libraries. This article shows you some of the approaches.

Use open source cross-platform libraries

There are some Microsoft recommended open source libraries to use:

Microsoft MAUI actually uses some of these libraries as the following table shows:

Platform Supported Abstractions
Xamarin.iOS CoreGraphics & SkiaSharp
Xamarin.Android Android.Graphics & SkiaSharp
Xamarin.Mac CoreGraphics & SkiaSharp
WPF SharpDX, SkiaSharp, Xaml & GDI
UWP SharpDX, Win2D, Xaml, SkiaSharp
WinForms SharpDX, SkiaSharp & GDI
Tizen SkiaSharp
Linux SkiaSharp
Xamarin.Forms Dependent on native platform support (noted above)

Use commercial libraries

For companies that can afford it and also need support, you can consider using some commercial software. You can Google to find out those available commercial libraries.

SVG libraries

If you are using .NET image processing libraries simply to render captcha code, you might consider implementing a similar solution like svg-captcha - npm (npmjs.com). This package is based on opentype.js.

There are no .NET project for it yet but you can use JavaScript services to run Node.js code in .NET application: Use JavaScript Services to Create Single Page Applications in ASP.NET Core | Microsoft Docs. There are two primary packages related:

You may also consider using implementing similar SVG captcha using pure .NET. For example, the following library can be used to load fonts.

watertrans/GlyphLoader: GlyphLoader is a .NET Standerd library for TrueType, OpenType font. (github.com)

I may publish one article about how to implement this in .NET 6 if there is large demand.

warning  Warning - In general, SVG implemented captcha code might not be as secured as bitmap image captchas. 

What are the other libraries you use to process images in .NET? Feel free to publish a comment here.

.net

Join the Discussion

View or add your thoughts below

Comments