Cast to AnyBitmap
In order to use and manipulate any image file in IronDrawing, all files must be converted to an AnyBitmap
file. For files from other platforms, IronDrawing 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 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 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 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.