IRONSOFTWAREHOME
Cast to AnyBitmap
using IronSoftware.Drawing;
using System.IO;

// We create an AnyBitmap object. We will then cast other popular types to Anybitmap.
AnyBitmap anyBitmap;

// Cast System.Drawing bitmap to AnyBitmap
System.Drawing.Bitmap bitmapFromBitmap = new System.Drawing.Bitmap(@"FILE_PATH");
anyBitmap = bitmapFromBitmap;

// Cast System image to AnyBitmap
System.Drawing.Image bitmapFromFile = System.Drawing.Image.FromFile(@"FILE_PATH");
anyBitmap = bitmapFromFile;

// Cast SKBitmap to AnyBitmap
SkiaSharp.SKBitmap skiaBitmap = SkiaSharp.SKBitmap.Decode(@"FILE_PATH");
anyBitmap = skiaBitmap;

// Cast SKimage to AnyBitmap
SkiaSharp.SKImage skiaImage = SkiaSharp.SKImage.FromBitmap(SkiaSharp.SKBitmap.Decode(@"FILE_PATH"));
anyBitmap = skiaImage;

// Cast SixLabors Image to AnyBitmap
SixLabors.ImageSharp.Image<SixLabors.ImageSharp.PixelFormats.Rgba32> imgSharp = SixLabors.ImageSharp.Image.Load<SixLabors.ImageSharp.PixelFormats.Rgba32>(@"FILE_PATH");
anyBitmap = imgSharp;

// Cast Maui image to AnyBitmap (not for NET 4.7.2):
byte[] imageAsBytes = File.ReadAllBytes(@"FILE_PATH");
// var mauiPlatformImage = Microsoft.Maui.Graphics.Platform.PlatformImage.FromStream(new MemoryStream(imageAsBytes));

NuGet Download
PM > Install-Package IronSoftware.System.Drawing
Cast to AnyBitmap

Cast to AnyBitmap

In order to use and manipulate any image file in IronSoftware.System.Drawing, all files must be converted to an AnyBitmap file. For files from other platforms, IronSoftware.System.Drawing can cast these files to AnyBitmap files. Below are examples of how image files from other platforms can be cast to an AnyBitmap file.

System.Drawing.Bitmap

A bitmap from System.Drawing can be cast to an AnyBitmap file. Begin by loading a System.Drawing.Bitmap file from a file path using System.Drawing.Bitmap, then cast the file by assigning it to a variable initialized with the AnyBitmap type.

System.Drawing.Image

Casting images from System.Drawing.Image can be done by loading the file from a file path using System.Drawing.Image.FromFile and storing it in a variable with the AnyBitmap type.

SkiaSharp.SKBitmap

Casting a bitmap from SkiaSharp can be done by initializing a SkiaSharp.SKBitmap variable and storing the file loaded from a file path using SkiaSharp.SKBitmap.Decode. The file can then be cast to an AnyBitmap type.

SkiaSharp.SKImage

To load a SkiaSharp image, load the file using SkiaSharp.SKImage.FromBitmap from a decoded SkiaSharp.SKBitmap, then store it inside a SkiaSharp.SKImage variable. It can be cast to an AnyBitmap file by assigning it to a variable of the AnyBitmap type.

SixLabors

Images from SixLabors can be loaded from a file path using SixLabors.ImageSharp.Image.Load<SixLabors.ImageSharp.PixelFormats.Rgba32> and stored in a SixLabors.ImageSharp.Image<SixLabors.ImageSharp.PixelFormats.Rgba32> variable. It can then be cast to an AnyBitmap file.

MAUI Image

Casting a MAUI image to an AnyBitmap file can only be done in environments other than NET4.7.2. A MAUI image file can be loaded by reading the bytes of the image obtained from a file path using File.ReadAllBytes, then storing the bytes in a byte[] array. The bytes must be translated into an image using Microsoft.Maui.Graphics.Platform.PlatformImage.FromStream and can then be cast to an AnyBitmap file.

View on GitHub

Ready to Get Started?

Nuget Downloads 20,033,450Version:2025.3just released

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.

OR
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 Iron Suite
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