IRONSOFTWAREHOME

AnyBitmap to System.Drawing.Bitmap in .NET Framework

Curtis Chau
Curtis Chau
Updated: June 24, 2026

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'
Text

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();
C#

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
SHELL

Package Manager Console:

Install-Package System.Drawing.Common
SHELL

SDK-style .csproj:

<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
}
C#

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

Please note: You 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,422,100Version:2026.9just released

Get your free 30-day Trial Key instantly.
No credit card or account creation required
C# NuGet Library for PDF
Install with NuGet

Version: 2026.9

PM > Install-Package BarCode
nuget.org/packages/BarCode/
  1. In Solution Explorer, right-click References, Manage NuGet Packages
  2. Select Browse and search "IronBarCode"
  3. Select the package and install
C# PDF DLL
Download DLL

Version: 2026.9

  1. Download and unzip IronBarCode to a location such as ~/Libs within your Solution directory
  2. In Visual Studio Solution Explorer, right click References. Select Browse, "IronBarCode.dll"

Licenses from $999

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required