Generate AnyBitmap

In order for users to use the IronDrawing tool to open, read, and manipulate image files, AnyBitmap type files must first be generated. There are a number of methods to load image files and generate AnyBitmap files.

File Path

Image files can be loaded from the local machine by using the AnyBitmap.FromFile(@"FILE_PATH") method. This method loads an image file from the given file path and stores it into an AnyBitmap variable, thus generating an AnyBitmap file.

// Load an image file from a file path and generate an AnyBitmap file
AnyBitmap bitmap = AnyBitmap.FromFile(@"C:\Path\To\Image\File.jpg");
// Load an image file from a file path and generate an AnyBitmap file
AnyBitmap bitmap = AnyBitmap.FromFile(@"C:\Path\To\Image\File.jpg");
' Load an image file from a file path and generate an AnyBitmap file
Dim bitmap As AnyBitmap = AnyBitmap.FromFile("C:\Path\To\Image\File.jpg")
$vbLabelText   $csharpLabel

Memory Stream

An AnyBitmap file can also be generated from a memory stream. The bytes of an image will be read and stored in byte arrays using the File.ReadAllBytes(@"FILE_PATH") method. The AnyBitmap file will then be generated from the bytes and stored in an AnyBitmap variable using the AnyBitmap.FromBytes(byte[]) method.

using System.IO;

// Read all bytes from the image file
byte[] imageBytes = File.ReadAllBytes(@"C:\Path\To\Image\File.jpg");
// Generate an AnyBitmap object from the bytes
AnyBitmap bitmap = AnyBitmap.FromBytes(imageBytes);
using System.IO;

// Read all bytes from the image file
byte[] imageBytes = File.ReadAllBytes(@"C:\Path\To\Image\File.jpg");
// Generate an AnyBitmap object from the bytes
AnyBitmap bitmap = AnyBitmap.FromBytes(imageBytes);
Imports System.IO

' Read all bytes from the image file
Private imageBytes() As Byte = File.ReadAllBytes("C:\Path\To\Image\File.jpg")
' Generate an AnyBitmap object from the bytes
Private bitmap As AnyBitmap = AnyBitmap.FromBytes(imageBytes)
$vbLabelText   $csharpLabel

SVG File

AnyBitmap can also be generated from an SVG file using the file path, similar to generating AnyBitmap from a normal file path. However, to load an SVG file into the program, additional dependencies such as SkiaSharp and SkiaSharp.Svg must be added.

// Example demonstrating the need for SkiaSharp and SkiaSharp.Svg to handle SVG files

// Load the SVG as AnyBitmap using the file path
AnyBitmap svgBitmap = AnyBitmap.FromFile(@"C:\Path\To\Vector\File.svg");
// Example demonstrating the need for SkiaSharp and SkiaSharp.Svg to handle SVG files

// Load the SVG as AnyBitmap using the file path
AnyBitmap svgBitmap = AnyBitmap.FromFile(@"C:\Path\To\Vector\File.svg");
' Example demonstrating the need for SkiaSharp and SkiaSharp.Svg to handle SVG files

' Load the SVG as AnyBitmap using the file path
Dim svgBitmap As AnyBitmap = AnyBitmap.FromFile("C:\Path\To\Vector\File.svg")
$vbLabelText   $csharpLabel

Uniform Resource Identifier (URI)

IronDrawing can also generate an AnyBitmap directly from a URI. Users need to initiate and store the URI path into a Uri type variable. The AnyBitmap file is generated by passing the Uri variable to the AnyBitmap.FromUri(uri) method.

using System;

// Create a Uri object from a URI string
Uri uri = new Uri("https://example.com/path/to/image.jpg");

// Generate an AnyBitmap object from the URI
AnyBitmap bitmap = AnyBitmap.FromUri(uri);
using System;

// Create a Uri object from a URI string
Uri uri = new Uri("https://example.com/path/to/image.jpg");

// Generate an AnyBitmap object from the URI
AnyBitmap bitmap = AnyBitmap.FromUri(uri);
Imports System

' Create a Uri object from a URI string
Private uri As New Uri("https://example.com/path/to/image.jpg")

' Generate an AnyBitmap object from the URI
Private bitmap As AnyBitmap = AnyBitmap.FromUri(uri)
$vbLabelText   $csharpLabel