Class ImageHelper
- Namespace
- VisioForge.Core.Helpers
- Assembly
- VisioForge.Core.dll
Provides comprehensive image processing utilities for RGB/RGBA image manipulation, stride calculations, and pixel format conversions. This static helper class handles low-level image operations including memory copying, color format conversions, image flipping, and stride calculations for various pixel formats (RGB24, RGB32, ARGB). Essential for video frame processing and image manipulation operations across the VisioForge media framework.
public static class ImageHelperInheritance
Inherited Members
Methods
DrawRGBImage(nint, int, int, nint, int, int, int, bool, ILogger)
Copies an uncompressed RGB image from a source buffer to a destination buffer at specified coordinates. Supports both RGB24 (3 bytes per pixel) and RGB32 (4 bytes per pixel) formats.
public static void DrawRGBImage(nint src, int srcWidth, int srcHeight, nint dest, int destWidth, int x, int y, bool draw32b, ILogger logger)Parameters
srcnint-
Pointer to the source image buffer containing raw RGB pixel data.
srcWidthint-
Width of the source image in pixels.
srcHeightint-
Height of the source image in pixels.
destnint-
Pointer to the destination image buffer where the image will be drawn.
destWidthint-
Width of the destination image in pixels (used for stride calculation).
xint-
X-coordinate in the destination image where the source image will be placed.
yint-
Y-coordinate in the destination image where the source image will be placed.
draw32bbool-
If true, processes as RGB32 format (4 bytes per pixel); if false, processes as RGB24 format (3 bytes per pixel).
loggerILogger-
Optional logger instance for error reporting. Pass null to disable logging.
FlipRGBImage(byte[], int, int)
Flips an RGB24 image vertically by reversing the order of scan lines. This is commonly needed when working with bitmap formats that store pixels bottom-up.
public static byte[] FlipRGBImage(byte[] data, int width, int height)Parameters
databyte[]-
The raw RGB24 image data as a byte array (3 bytes per pixel).
widthint-
The width of the image in pixels.
heightint-
The height of the image in pixels.
Returns
- byte[]
-
A new byte array containing the vertically flipped image data.
GetStrideByPixelSize(int, byte)
Calculates the stride (bytes per row) for an image based on arbitrary pixel size. The stride is aligned to 4-byte boundaries for optimal memory access.
public static int GetStrideByPixelSize(int width, byte pixelSize)Parameters
widthint-
The width of the image in pixels.
pixelSizebyte-
The size of each pixel in bytes (e.g., 3 for RGB24, 4 for RGB32).
Returns
- int
-
The stride value in bytes, aligned to 4-byte boundaries.
GetStrideRGB(int, PixelFormatX)
Calculates the stride (bytes per row) for an RGB image based on its width and pixel format. The stride is aligned to 4-byte boundaries as required by many graphics APIs.
public static int GetStrideRGB(int width, PixelFormatX pixelFormat)Parameters
widthint-
The width of the image in pixels.
pixelFormatPixelFormatX-
The pixel format of the image (Format24bppRgb, Format32bppArgb, etc.).
Returns
- int
-
The stride value in bytes, aligned to 4-byte boundaries. Returns 0 for unsupported formats.
GetStrideRGB24(int)
Calculates the stride (bytes per row) for an RGB24 image (3 bytes per pixel). The stride is aligned to 4-byte boundaries for optimal memory access.
public static int GetStrideRGB24(int width)Parameters
widthint-
The width of the image in pixels.
Returns
- int
-
The stride value in bytes, aligned to 4-byte boundaries.
GetStrideRGB32(int)
Calculates the stride (bytes per row) for an RGB32 image (4 bytes per pixel). The stride is aligned to 4-byte boundaries for optimal memory access.
public static int GetStrideRGB32(int width)Parameters
widthint-
The width of the image in pixels.
Returns
- int
-
The stride value in bytes, aligned to 4-byte boundaries.
GetStrideYUY2(int)
Calculates the stride (bytes per row) for a YUY2 image format. YUY2 uses 2 bytes per pixel in a packed format (Y0 U0 Y1 V0).
public static int GetStrideYUY2(int width)Parameters
widthint-
The width of the image in pixels.
Returns
- int
-
The stride value in bytes (width * 2).
MakeCOLORREF(byte, byte, byte)
Creates a COLORREF value from individual red, green, and blue color components.
public static int MakeCOLORREF(byte r, byte g, byte b)Parameters
rbyte-
The red component value (0-255).
gbyte-
The green component value (0-255).
bbyte-
The blue component value (0-255).
Returns
- int
-
A 32-bit integer representing the COLORREF value in Windows GDI format (0x00BBGGRR).