GH_MemoryBitmap

References
public sealed class GH_MemoryBitmap
Utility class for ultra-fast bitmap sampling and filters.

Constructors

GH_MemoryBitmap

#
public GH_MemoryBitmap(Bitmap bitmap, WrapMode wrap)
Constructor with Wrap mode override.
bitmap (Bitmap)Bitmap to operate on. This bitmap will be in an invalid state until the Release() function has been called.
wrap (WrapMode)Wrap mode to use during sampling.

GH_MemoryBitmap

#
public GH_MemoryBitmap(Bitmap bitmap)
Default constructor.
bitmap (Bitmap)Bitmap to operate on. This bitmap will be in an invalid state until the Release() function has been called.

Properties

HasAlphaChannel

#
public bool HasAlphaChannel { get; }
Gets a value indicating whether or not the local image has an alpha channel defined.

Height

#
public int Height { get; }
Gets the height (in pixels) of the local image.

SizeOf

#
public int SizeOf { get; }
Gets the size (in bytes) of the local image.

Width

#
public int Width { get; }
Gets the width (in pixels) of the local image.

Methods

A

#
public byte A(int x, int y)
Gets the alpha channel value at the given pixel coordinates.
x (int)X coordinate (column) of pixel. Must be on image interior.
y (int)Y coordinate (column) of pixel. Must be on image interior.
Value of alpha channel at given pixel or 255 if the alpha channel is not defined.

B

#
public byte B(int x, int y)
Gets the blue channel value at the given pixel coordinates.
x (int)X coordinate (column) of pixel. Must be on image interior.
y (int)Y coordinate (column) of pixel. Must be on image interior.
Value of Blue channel at given pixel.

Colour

#
public Color Colour(int x, int y)
Gets the colour at the given pixel coordinates.
x (int)X coordinate (column) of pixel. Must be on image interior.
y (int)Y coordinate (column) of pixel. Must be on image interior.
Colour at given pixel.

Colour

#
public void Colour(int x, int y, Color col)
Sets the colour at the given pixel coordinates.
x (int)X coordinate (column) of pixel. Must be on image interior.
y (int)Y coordinate (column) of pixel. Must be on image interior.
col (Color)Color to assign.

CopyChannel

#
public void CopyChannel(GH_BitmapChannel source, GH_BitmapChannel target)
Copy the contents of one channel into another.
source (GH_BitmapChannel)Source channel (compound channels are not allowed).
target (GH_BitmapChannel)Target channel (compound channels are not allowed).

Filter_AlphaEdges

#
public void Filter_AlphaEdges(Padding padding, byte alpha_override)
Set the alpha component on all edges to a specific value.
padding (Padding)Width of alpha band along all edges. Must be a valid padding construct.
alpha_override (byte)Value of alpha to apply.

Filter_Blur

#
public void Filter_Blur()
Blur the image in both directions.

Filter_Blur

#
public void Filter_Blur(int interior_weight, int exterior_weight)
Blur the image in both directions.
interior_weight (int)Weighting factor for pixels at the center of the convolution matrix.
exterior_weight (int)Weighting factor for pixels at the edges of the convolution matrix.

Filter_Blur

#
public void Filter_Blur(int N, int interior_weight, int exterior_weight)
Blur the image N times in both directions.
N (int)Number of times to perform the blurring operation.
interior_weight (int)Weighting factor for pixels at the center of the convolution matrix.
exterior_weight (int)Weighting factor for pixels at the edges of the convolution matrix.

Filter_Blur

#
public void Filter_Blur(int N)
Blur the image N times in both directions.
N (int)Number of times to perform the blurring operation.

Filter_BlurAlpha

#
public void Filter_BlurAlpha(int N, int interior_weight, int exterior_weight)
Blur the alpha channel of the image N times in both directions.
N (int)Number of times to perform the blurring operation.
interior_weight (int)Weighting factor for pixels at the center of the convolution matrix.
exterior_weight (int)Weighting factor for pixels at the edges of the convolution matrix.

Filter_Contrast

#
public void Filter_Contrast(GH_BitmapChannel channel, double factor)
Adjust the contrast of a specific channel.
channel (GH_BitmapChannel)Channel(s) to modify.
factor (double)Contrast boost factor. A factor of 1.0 will not affect contrast. Lower values will lessen contrast and higher values will increase contrast.

Filter_DitherPattern

#
public void Filter_DitherPattern(Color colour)
Create a checkerboard dither pattern.
colour (Color)Colour value to set at dithered pixels.

Filter_DropShadow

#
public void Filter_DropShadow(Size offset, int blur, double darkness)
Add a drop-shadow to the image. Image is not grown, so if you want the drop shadow to extend beyond the image boundaries, you have to add padding to the image first.
offset (Size)Number of pixels (x and y) to offset the drop shadow.
blur (int)Amount of blurring for the shadow.
darkness (double)Darkness factor for the shadow.

Filter_Dullify

#
public void Filter_Dullify()
Reduces contrast based on opacity. This filter pulls all colours towards dull grey, without wrecking drop-shadows.

Filter_Equalize

#
public void Filter_Equalize(GH_BitmapChannel channel, byte value)
Set all the values in a specific channel to a specific value.
channel (GH_BitmapChannel)Channel(s) to equalize.
value (byte)Value to equalize with.

Filter_GreyScale

#
public void Filter_GreyScale()
Convert the image to a greyscale shadow of its former self.

Filter_GreyScale

#
public void Filter_GreyScale(double amount)
Convert the image to a greyscale shadow of its former self.
amount (double)Greyscale factor. 1.0 equals complete greyscale, 0.0 equals no greyscale, -1.0 equals inverse greyscale

Filter_HueScale

#
public void Filter_HueScale()
Convert the image to a greyscale representation of the hues.

Filter_Invert

#
public void Filter_Invert(GH_BitmapChannel channel)
Invert all values in a specific channel.
channel (GH_BitmapChannel)Channel(s) to invert.

Filter_LumScale

#
public void Filter_LumScale()
Convert the image to a greyscale representation of the luminance.

Filter_Multiply

#
public void Filter_Multiply(GH_BitmapChannel channel, double factor, byte anchor)
Multiply all values in a specific channel with a specific factor, using a custom scaling center anchor.
channel (GH_BitmapChannel)Channel(s) to multiply.
factor (double)Multiplication factor.
anchor (byte)Byte value to scale from.

Filter_Multiply

#
public void Filter_Multiply(GH_BitmapChannel channel, double factor)
Multiply all values in a specific channel with a specific factor.
channel (GH_BitmapChannel)Channel(s) to multiply.
factor (double)Multiplication factor.

Filter_SatScale

#
public void Filter_SatScale()
Convert the image to a greyscale representation of the saturation.

Filter_Shift

#
public void Filter_Shift(GH_BitmapChannel channel, byte amount)
Shift all values in a specific channel with a specific amount.
channel (GH_BitmapChannel)Channel(s) to shift.
amount (byte)Shift amount.

Filter_SpectrumScale

#
public void Filter_SpectrumScale()
Convert the image to a spectral representation of the hues.

Filter_Tint

#
public void Filter_Tint(Color tint, double lum_factor, double sat_factor)
Colorize the image using Hue and Saturation from a base colour.
tint (Color)Colour of colorize operation.
lum_factor (double)Luminance blend factor. 0.0 equals no luminance adjustment, 1.0 equals complete luminance adjustment.
sat_factor (double)Saturation blend factor. 0.0 equals no saturation adjustment, 1.0 equals complete saturation adjustment.

Finalize

#
protected override void Finalize()
Object.Finalize

G

#
public byte G(int x, int y)
Gets the greeb channel value at the given pixel coordinates.
x (int)X coordinate (column) of pixel. Must be on image interior.
y (int)Y coordinate (column) of pixel. Must be on image interior.
Value of Green channel at given pixel.

OpaqueArea

#
public Rectangle OpaqueArea()
Find the opaque area of a bitmap. The opaque area is the rectangle that contains pixels with a colour that is not fully transparent.
Area of bitmap containing all non-transparent pixels.

PadBitmap

#
public static Bitmap PadBitmap(Image bmp, Padding padding, Color padding_color)
Add padding edges around a bitmap.
bmp (Image)Source bitmap.
padding (Padding)Padding to apply.
padding_color (Color)Color of padded edges.
A new bitmap with padded edges and the same PixelFormat as the original bitmap.

R

#
public byte R(int x, int y)
Gets the red channel value at the given pixel coordinates.
x (int)X coordinate (column) of pixel. Must be on image interior.
y (int)Y coordinate (column) of pixel. Must be on image interior.
Value of Red channel at given pixel.

Release

#
public void Release(bool includeChanges)
Release the locked bits. You must call this function when you are done with this GH_MemoryBitmap instance.
includeChanges (bool)If true, changes to the bitmap memory block will be written back into the bitmap.

Sample

#
public bool Sample(double x, double y, ref Color col)
Top level sampling function for interpolated sampling.
x (double)floating point coordinate in pixel space.
y (double)floating point coordinate in pixel space.
col (ref Color)Resulting colour

Sample

#
public bool Sample(int x, int y, ref Color col)
Top level sampling function.
x (int)Unmapped x pixel coordinate.
y (int)Unmapped y pixel coordinate.
col (ref Color)Colour output.
True on success, false if pixels could not be sampled.

ShrinkBitmap

#
public static Bitmap ShrinkBitmap(Bitmap image)
Shrink an image by removing all outer columns and rows that contain only fully transparent pixels.
image (Bitmap)Image to shrink.
Shrunk bitmap.