C# Bitmap Library to Replace System.Drawing.Common in .NET

IronDrawing is free, open-source, and supports most .NET drawing library formats

IronDrawing is an open-source library originally developed by Iron Software that helps C# Software Engineers to replace System.Drawing.Common in .NET projects on Windows, macOS and Linux platforms.

Developing class libraries and NuGet packages for .NET 5, 6, 7 & 8 that support graphics, images and fonts should be easy.

IronDrawing acts as a seamless bridge between all the new proposed .NET 5, 6, 7 & 8 graphics standards as they evolve - so you only need to develop for the one you prefer.

IronDrawing is free, open-source, and supports most .NET drawing library formats

Context

Microsoft .NET is a multi-platform, highly compatible​ software framework used by millions of software developers across the globe. Microsoft has announced a breaking change in which System.Drawing.Common will only be supported on Windows platforms.

This is problematic for .NET library developers who maintain cross-platform libraries that use System.Drawing.Common because Microsoft's recommended action requires you to rebuild your library to support non-Windows users. Volunteers and academics are expected to rebuild every NuGet package and class library to use each of the new suggested graphics libraries as they emerge, causing a technical debt which will slow adoption of modern .NET.

Ultimately, when we use .NET, we use NuGet.

NuGet package developers are doing us all favor by advancing .NET and pre-packaged code that would take thousands of hours to write ourselves every day.

This breaking change will slow NuGet development and could lead to abandoned or obsolete code libraries which .NET developers depend upon. We need to act now!

Our Solution

An intermediary graphics formats that converts between all the old and new graphics libraries.

As a class library developer your public Bitmap, Color, Rectangle, Font, and Size Inputs and Outputs can be of only one type that supports All the new standards. Internally, you can continue to do what you like.

IronDrawing is backwards compatible with .NET Framework 4.62, supports all versions of .NET (including .NET 8).

The development and release of IronDrawing solves this issue by providing an open-source solution to the lack of a uniform format for important classes such as Bitmap, Color, Rectangle, Font, and Size. IronSoftware.Drawing will seamlessly convert between the implementations of these type in System.Drawing, Microsoft.Maui, SkiaSharp, and SixLabors for you. This allows you, the developer, to not have to replace all instances of these classes within your library.

For example, if you are using System.Drawing.Bitmap, you may use IronDrawing's AnyBitmap class which has implicit conversions to any of these types: System.Drawing.Bitmap, System.Drawing.Image, SkiaSharp.SKBitmap, SkiaSharp.SKImage, SixLabors.ImageSharp, Microsoft.Maui.Graphics.Platform.PlatformImage.

Why Are We Doing This for Free

We have developed IronDrawing because we at Iron Software are long-term senior .NET developers who care about the evolution of .NET and want it to grow and succeed. We love to see that .NET is growing and evolving, as seen with .NET 7. We use NuGet all day, and I'm sure you do too. We support and hope to encourage an easy transition to the future and away from System.Drawing.

We want all .NET class-library and NuGet development to be easier, so that the NuGet Ecosystem continues to thrive, and so that all .NET developers benefit.

IronSoftware.Drawing Features

  • AnyBitmap: A universally compatible Bitmap class. Implicit casting between IronSoftware.Drawing.AnyBitmap and the following supported:
    • System.Drawing.Bitmap
    • System.Drawing.Image
    • SkiaSharp.SKBitmap
    • SkiaSharp.SKImage
    • SixLabors.ImageSharp
    • Microsoft.Maui.Graphics.Platform.PlatformImage
  • Color: A universally compatible Color class. Implicit casting between IronSoftware.Drawing.Color and the following supported:
    • System.Drawing.Color
    • SkiaSharp.SKColor
    • SixLabors.ImageSharp.Color
    • SixLabors.ImageSharp.PixelFormats
  • Rectangle: A universally compatible Rectangle class. Implicit casting between IronSoftware.Drawing.Rectangle and the following supported:
    • System.Drawing.Rectangle
    • SkiaSharp.SKRect
    • SkiaSharp.SKRectI
    • SixLabors.ImageSharp.Rectangle
  • Font: A universally compatible Font class. Implicit casting between IronSoftware.Drawing.Font and the following supported:
    • System.Drawing.Font
    • SkiaSharp.SKFont
    • SixLabors.Fonts.Font

Compatibility

IronSoftware.Drawing has cross-platform support compatibility with:

  • .NET 8, .NET 7, .NET 6, .NET 5, .NET Core, .NET Standard, and .NET Framework 4.62+
  • Windows, macOS, Linux, Docker, Azure, and AWS

Installation

​Installing the IronDrawing (IronSoftware.Drawing) NuGet package is quick and easy. Please install the package like this:

Install-Package IronSoftware.System.Drawing

Alternatively, download directly from the official NuGet website.

Once installed, you can get started by adding using IronSoftware.Drawing; to the top of your C# code.

Code Examples

AnyBitmap Example

:path=/static-assets/drawing/content-code-examples/get-started/anybitmap.cs
using IronSoftware.Drawing;
​
// Create a new AnyBitmap object
var bitmap = AnyBitmap.FromFile("FILE_PATH");
bitmap.SaveAs("result.jpg");
​
var bytes = bitmap.ExportBytes();
​
var resultExport = new System.IO.MemoryStream();
bitmap.ExportStream(resultExport, AnyBitmap.ImageFormat.Jpeg, 100);
​
// Casting between System.Drawing.Bitmap and IronSoftware.Drawing.AnyBitmap
System.Drawing.Bitmap image = new System.Drawing.Bitmap("FILE_PATH");
IronSoftware.Drawing.AnyBitmap anyBitmap = image;
anyBitmap.SaveAs("result-from-casting.png");
Imports IronSoftware.Drawing

' Create a new AnyBitmap object
Private bitmap = AnyBitmap.FromFile("FILE_PATH")
bitmap.SaveAs("result.jpg")

Dim bytes = bitmap.ExportBytes()

Dim resultExport = New System.IO.MemoryStream()
bitmap.ExportStream(resultExport, AnyBitmap.ImageFormat.Jpeg, 100)

' Casting between System.Drawing.Bitmap and IronSoftware.Drawing.AnyBitmap
Dim image As New System.Drawing.Bitmap("FILE_PATH")
Dim anyBitmap As IronSoftware.Drawing.AnyBitmap = image
anyBitmap.SaveAs("result-from-casting.png")
VB   C#

Color Example

:path=/static-assets/drawing/content-code-examples/get-started/color.cs
using IronSoftware.Drawing;
​
// Create a new Color object
Color fromHex = new Color("#191919");
Color fromRgb = new Color(255, 255, 0);
Color fromEnum = Color.Crimson;
​
// Casting between System.Drawing.Color and IronSoftware.Drawing.Color
System.Drawing.Color drawingColor = System.Drawing.Color.Red;
IronSoftware.Drawing.Color ironColor = drawingColor;
​
ironColor.A;
ironColor.R;
ironColor.G;
ironColor.B;
​
// Luminance is a value from 0 (black) to 100 (white) where 50 is the perceptual "middle grey"
IronDrawingColor.GetLuminance();
Imports IronSoftware.Drawing

' Create a new Color object
Private fromHex As New Color("#191919")
Private fromRgb As New Color(255, 255, 0)
Private fromEnum As Color = Color.Crimson

' Casting between System.Drawing.Color and IronSoftware.Drawing.Color
Private drawingColor As System.Drawing.Color = System.Drawing.Color.Red
Private ironColor As IronSoftware.Drawing.Color = drawingColor

ironColor.A
ironColor.R
ironColor.G
ironColor.B

' Luminance is a value from 0 (black) to 100 (white) where 50 is the perceptual "middle grey"
IronDrawingColor.GetLuminance()
VB   C#

Rectangle Example

:path=/static-assets/drawing/content-code-examples/get-started/rectangle.cs
using IronSoftware.Drawing;
​
// Create a new Rectangle object
Rectangle Rectangle = new Rectangle(5, 5, 50, 50);
​
// Casting between System.Drawing.Rectangle and IronSoftware.Drawing.Rectangle
System.Drawing.Rectangle rectangle = new System.Drawing.Rectangle(10, 10, 150, 150);
IronSoftware.Drawing.Rectangle ironRectangle = rectangle;
​
ironRectangle.X;
ironRectangle.Y;
ironRectangle.Width;
ironRectangle.Height;
Imports IronSoftware.Drawing

' Create a new Rectangle object
Private Rectangle As New Rectangle(5, 5, 50, 50)

' Casting between System.Drawing.Rectangle and IronSoftware.Drawing.Rectangle
'INSTANT VB NOTE: The field rectangle was renamed since Visual Basic does not allow fields to have the same name as other class members:
Private rectangle_Conflict As New System.Drawing.Rectangle(10, 10, 150, 150)
Private ironRectangle As IronSoftware.Drawing.Rectangle = rectangle_Conflict

ironRectangle.X
ironRectangle.Y
ironRectangle.Width
ironRectangle.Height
VB   C#

Font Example

:path=/static-assets/drawing/content-code-examples/get-started/font.cs
using IronSoftware.Drawing;
​
// Create a new Font object
Font font = new Font("Times New Roman", FontStyle.Italic | FontStyle.Bold, 30);
​
// Casting between System.Drawing.Font and IronSoftware.Drawing.Font
System.Drawing.Font drawingFont = new System.Drawing.Font("Courier New", 30);
IronSoftware.Drawing.Font ironFont = drawingFont;
​
ironFont.FamilyName;
ironFont.Style;
ironFont.Size;
ironFont.Italic;
ironFont.Bold;
Imports IronSoftware.Drawing

' Create a new Font object
Private font As New Font("Times New Roman", FontStyle.Italic Or FontStyle.Bold, 30)

' Casting between System.Drawing.Font and IronSoftware.Drawing.Font
Private drawingFont As New System.Drawing.Font("Courier New", 30)
Private ironFont As IronSoftware.Drawing.Font = drawingFont

ironFont.FamilyName
ironFont.Style
ironFont.Size
ironFont.Italic
ironFont.Bold
VB   C#

Support Available

License

The licensing information can be found here: LICENSE.txt

Contribute

If you would like to contribute to the IronDrawing open-source project, please read the license before making a pull-request to the repository on GitHub.

Information

For more information about Iron Software please visit our website: https://ironsoftware.com/

Support from Iron Software

For general support and technical inquiries, please email us at: mailto:support@ironsoftware.com