AnyBitmap to System.Drawing.Bitmap in .NET Framework

In a .NET Framework desktop app such as WinForms, assigning an IronBarcode AnyBitmap directly to a System.Drawing.Image or Bitmap fails at compile time. A common case is binding a generated barcode to a PictureBox, which only accepts System.Drawing.Image objects.

Cannot implicitly convert type 'IronSoftware.Drawing.AnyBitmap' to 'System.Drawing.Image'

The code below triggers the error:

var myBarcode = BarcodeWriter.CreateBarcode("12345", BarcodeWriterEncoding.EAN8);
// These lines cause compile-time errors
Image myBarcodeImage = myBarcode.Image;
Bitmap myBarcodeBitmap = myBarcode.ToBitmap();
var myBarcode = BarcodeWriter.CreateBarcode("12345", BarcodeWriterEncoding.EAN8);
// These lines cause compile-time errors
Image myBarcodeImage = myBarcode.Image;
Bitmap myBarcodeBitmap = myBarcode.ToBitmap();
Dim myBarcode = BarcodeWriter.CreateBarcode("12345", BarcodeWriterEncoding.EAN8)
' These lines cause compile-time errors
Dim myBarcodeImage As Image = myBarcode.Image
Dim myBarcodeBitmap As Bitmap = myBarcode.ToBitmap()
$vbLabelText   $csharpLabel

Both BarcodeWriter.Image and .ToBitmap() return an IronSoftware.Drawing.AnyBitmap. That type does support implicit conversion to System.Drawing.Bitmap or Image, but only on .NET 6, .NET 7, .NET 8, or higher. On .NET Framework the implicit operators and internal type bridging do not always resolve, especially when the types come from different libraries or compatibility layers.

Solution

Option 1: Install System.Drawing.Common

Add the System.Drawing.Common NuGet package so the conversion operators resolve against a consistent drawing assembly.

.NET CLI:

dotnet add package System.Drawing.Common
dotnet add package System.Drawing.Common
SHELL

Package Manager Console:

Install-Package System.Drawing.Common
Install-Package System.Drawing.Common
SHELL

SDK-style .csproj:

<PackageReference Include="System.Drawing.Common" Version="8.0.0" />
<PackageReference Include="System.Drawing.Common" Version="8.0.0" />
XML

Option 2: Convert Through a Stream

When you would rather not change package references, convert the bitmap through a GDI-compatible stream and hand the result to the PictureBox:

var myBarcode = BarcodeWriter.CreateBarcode("12345", BarcodeWriterEncoding.EAN8);
myBarcode.ResizeTo(400, 100); // Optional resizing
using (var ms = myBarcode.ToWindowsBitmapStream())
{
    pictureBox1.Image = Image.FromStream(ms); // Works in .NET Framework
}
var myBarcode = BarcodeWriter.CreateBarcode("12345", BarcodeWriterEncoding.EAN8);
myBarcode.ResizeTo(400, 100); // Optional resizing
using (var ms = myBarcode.ToWindowsBitmapStream())
{
    pictureBox1.Image = Image.FromStream(ms); // Works in .NET Framework
}
Dim myBarcode = BarcodeWriter.CreateBarcode("12345", BarcodeWriterEncoding.EAN8)
myBarcode.ResizeTo(400, 100) ' Optional resizing
Using ms = myBarcode.ToWindowsBitmapStream()
    pictureBox1.Image = Image.FromStream(ms) ' Works in .NET Framework
End Using
$vbLabelText   $csharpLabel

ToWindowsBitmapStream() writes the AnyBitmap to a GDI-compatible image format, and Image.FromStream parses that stream into a native System.Drawing.Image.

Please noteYou can also serialize the AnyBitmap with ToStream() if you need a generic stream rather than a Windows-specific one.

Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...

Read More
Ready to Get Started?
Nuget Downloads 2,295,550 | Version: 2026.7 just released
Still Scrolling Icon

Still Scrolling?

Want proof fast? PM > Install-Package BarCode
run a sample watch your string become a barcode.