Table of Contents

Class SkiaHelper

Namespace
VisioForge.Core.Helpers
Assembly
VisioForge.Core.dll

Provides helper methods for working with SkiaSharp bitmaps, including format conversions, image transformations, and interoperability with video frames.

public static class SkiaHelper

Inheritance

Inherited Members

Methods

ByteArrayRGBAToSKBitmap(byte[], int, int)

Converts a byte array containing RGBA pixel data to an SKBitmap.

public static SKBitmap ByteArrayRGBAToSKBitmap(byte[] frame, int width, int height)

Parameters

frame byte[]

The byte array containing RGBA pixel data.

width int

The width of the image in pixels.

height int

The height of the image in pixels.

Returns

SKBitmap

A new SKBitmap containing the converted image data.

ByteArrayRGBToSKBitmap(byte[], int, int)

Converts a byte array containing RGB pixel data to an SKBitmap. The RGB data is converted to RGBA format internally.

public static SKBitmap ByteArrayRGBToSKBitmap(byte[] frame, int width, int height)

Parameters

frame byte[]

The byte array containing RGB pixel data.

width int

The width of the image in pixels.

height int

The height of the image in pixels.

Returns

SKBitmap

A new SKBitmap containing the converted image data.

FlipHorizontal(SKBitmap)

Creates a new SKBitmap that is horizontally flipped (mirrored) from the original.

public static SKBitmap FlipHorizontal(this SKBitmap bmp)

Parameters

bmp SKBitmap

The original SKBitmap to flip.

Returns

SKBitmap

A new SKBitmap containing the horizontally flipped image.

FlipVertical(SKBitmap)

Creates a new SKBitmap that is vertically flipped from the original.

public static SKBitmap FlipVertical(this SKBitmap bmp)

Parameters

bmp SKBitmap

The original SKBitmap to flip.

Returns

SKBitmap

A new SKBitmap containing the vertically flipped image.

RGBAToSKBitmap(nint, int, int)

Converts an unmanaged memory pointer containing RGBA pixel data to an SKBitmap.

public static SKBitmap RGBAToSKBitmap(nint data, int width, int height)

Parameters

data nint

A pointer to unmanaged memory containing RGBA pixel data.

width int

The width of the image in pixels.

height int

The height of the image in pixels.

Returns

SKBitmap

A new SKBitmap containing the converted image data.

Rotate(SKBitmap, SKRotationAngle)

Rotates an SKBitmap by the specified angle.

public static SKBitmap Rotate(this SKBitmap originalBitmap, SKRotationAngle rotation)

Parameters

originalBitmap SKBitmap

The original SKBitmap to rotate.

rotation SKRotationAngle

The rotation angle to apply (90, 180, or 270 degrees).

Returns

SKBitmap

A new SKBitmap containing the rotated image with dimensions adjusted as necessary.

SaveToFile(SKBitmap, string, SKEncodedImageFormat, int)

Saves an SKBitmap to a file in the specified format.

public static void SaveToFile(this SKBitmap bitmap, string filename, SKEncodedImageFormat format = SKEncodedImageFormat.Png, int quality = 85)

Parameters

bitmap SKBitmap

The SKBitmap to save.

filename string

The full path and filename where the image will be saved.

format SKEncodedImageFormat

The image format to use for encoding. Defaults to PNG.

quality int

The quality level for lossy formats (0-100). Defaults to 85. Only applicable for formats like JPEG.

ToARGB(SKBitmap, out int)

Converts an SKBitmap to an ARGB byte array and returns a pointer to the allocated memory.

public static nint ToARGB(this SKBitmap bitmap, out int length)

Parameters

bitmap SKBitmap

The SKBitmap to convert.

length int

When this method returns, contains the length of the allocated memory in bytes.

Returns

nint

A pointer to unmanaged memory containing the ARGB data. The caller is responsible for freeing this memory using Marshal.FreeHGlobal.

VideoFrameBGRAToSKBitmap(VideoFrameX)

Converts a VideoFrameX containing BGRA data to an SKBitmap. This is a direct copy as SKBitmap uses BGRA format internally.

public static SKBitmap VideoFrameBGRAToSKBitmap(this VideoFrameX frame)

Parameters

frame VideoFrameX

The VideoFrameX containing BGRA pixel data.

Returns

SKBitmap

A new SKBitmap containing the image data.

VideoFrameRGBAToSKBitmap(VideoFrame)

Converts a VideoFrame containing RGBA data to an SKBitmap.

public static SKBitmap VideoFrameRGBAToSKBitmap(this VideoFrame frame)

Parameters

frame VideoFrame

The VideoFrame containing RGBA pixel data.

Returns

SKBitmap

A new SKBitmap containing the converted image data.

VideoFrameRGBAToSKBitmap(VideoFrameX)

Converts a VideoFrameX containing RGBA data to an SKBitmap. The RGBA data is converted to BGRA format to match SKBitmap's internal format.

public static SKBitmap VideoFrameRGBAToSKBitmap(this VideoFrameX frame)

Parameters

frame VideoFrameX

The VideoFrameX containing RGBA pixel data.

Returns

SKBitmap

A new SKBitmap containing the converted image data.

VideoFrameRGBToSKBitmap(VideoFrameX)

Converts a VideoFrameX containing RGB data to an SKBitmap. The RGB data is converted to BGRA format to match SKBitmap's internal format.

public static SKBitmap VideoFrameRGBToSKBitmap(this VideoFrameX frame)

Parameters

frame VideoFrameX

The VideoFrameX containing RGB pixel data.

Returns

SKBitmap

A new SKBitmap containing the converted image data.