BitmapExtensionMethods

public static class BitmapExtensionMethods
Extension methods for Eto.Drawing.Bitmap

Methods

AddHsla

#Example
public static void AddHsla(this BitmapData data, float hue, float saturation, float luminance, float alpha)
Add a constant to all values in HSL channels.
data (BitmapData)Bitmap to modify.
hue (float)Hue channel multiplication factor.
saturation (float)Saturation channel multiplication factor.
luminance (float)Luminance channel multiplication factor.
alpha (float)Alpha channel multiplication factor.

AddRgba

#Example
public static void AddRgba(this BitmapData data, float red, float green, float blue, float alpha)
Add a constant to all channel values.
data (BitmapData)Bitmap to modify.
red (float)Red channel addend.
green (float)Green channel addend.
blue (float)Blue channel addend.
alpha (float)Alpha channel addend.

ApplyFilterDelegate

#Example
public static void ApplyFilterDelegate(this BitmapData data, Func<Color, Color> filter)
Apply a custom filter delegate to a bitmap.
data (BitmapData)Bitmap to modify.
filter (Func<Color, Color>)Filter to apply.
public static void Blur(this BitmapData data, BlurProfile profile, int x, int y, int iterations)
Blur an image.
data (BitmapData)Bitmap to blur.
profile (BlurProfile)Blurring profile to use.
x (int)Horizontal blurring radius.
y (int)Vertical blurring radius.
iterations (int)Number of successive blurring operations to perform.
public static void Blur(this BitmapData data, float[] xProfile, float[] yProfile, int iterations)
Apply a custom blurring curve.
data (BitmapData)Bitmap data to operate on.
xProfile (float[])Array of horizontal weighting factors. The first value equals the weight at the pixel itself, with every additional value indicating the weight of the next pixel. The length of the array thus specified the horizontal blurring radius.
yProfile (float[])Array of vertical weighting factors. The first value equals the weight at the pixel itself, with every additional value indicating the weight of the next pixel. The length of the array thus specified the vertical blurring radius.
iterations (int)Number of blurring iterations to run.

ClearCheckerBoard

#Example
public static void ClearCheckerBoard(this BitmapData data, Color a, Color b, int size)
Clear the entire image using a checkerboard pattern.
data (BitmapData)Bitmap data accessor.
a (Color)First colour.
b (Color)Second colour.
size (int)Square size.

ClearCheckerBoard

#Example
public static void ClearCheckerBoard(this BitmapData data, Color colour, int size)
Apply colour to half the pixels in an image using a checkerboard pattern.
data (BitmapData)Bitmap data accessor.
colour (Color)Colour.
size (int)Square size.

ClearRectangle

#Example
public static void ClearRectangle(this BitmapData data, Rectangle rectangle, Color color)
Set all pixels within a rectangle to a specific colour.
data (BitmapData)Bitmap to adjust.
rectangle (Rectangle)Rectangle.
color (Color)Color to assign to all pixels within rectangle.

CreateBlurProfile

#
public static float[] CreateBlurProfile(int radius, BlurProfile profile)
Create a blurring profile curve using a gaussian falloff.
radius (int)Radius of curve.
profile (BlurProfile)Profile type to create.
Blurring curve.

CreatePalette

#Example
public static Color[] CreatePalette(this Bitmap bitmap, int count, int accuracy, KdMeanType mean, bool alpha)
Create a custom sized palette containing the most relevant colours in a bitmap.
bitmap (Bitmap)Bitmap to sample.
count (int)Number of colours in palette. May not exceed 2^12 = 4096.
accuracy (int)Pixel accuracy between samples.
mean (KdMeanType)Mean computation algorithm.
alpha (bool)If true, alpha values will be included in the palette.
Array of colour representing the N most relevant colours in the bitmap.

CreatePalette

#Example
public static Color[] CreatePalette(this BitmapData data, int count, int accuracy, KdMeanType mean, bool alpha)
Create a custom sized palette containing the most relevant colours in a bitmap.
data (BitmapData)Bitmap to sample.
count (int)Number of colours in palette. May not exceed 2^12 = 4096.
accuracy (int)Pixel accuracy between samples.
mean (KdMeanType)Mean computation algorithm.
alpha (bool)If true, alpha values will be included in the palette.
Array of colour representing the N most relevant colours in the bitmap.

Dither

#Example
public static void Dither(this BitmapData data, IEnumerable<Color> palette, DitherAlgorithm algorithm)
Dither an image using a palette.
data (BitmapData)Bitmap to dither.
palette (IEnumerable<Color>)Collection of colours in palette.
algorithm (DitherAlgorithm)Dither algorithm to use.

Dither

#Example
public static void Dither(this BitmapData data, SpatialTree<Color> palette, DitherAlgorithm algorithm)
Dither an image using a palette.
data (BitmapData)Bitmap to dither.
palette (SpatialTree<Color>)Palette stored as spatial tree.
algorithm (DitherAlgorithm)Dither algorithm to use.

DrawArcGradient

#Example
public static void DrawArcGradient(this BitmapData data, Rectangle rectangle, Gradient gradient, Arc arc)
Draw an arc gradient into a rectangle.
data (BitmapData)Bitmap to draw onto.
rectangle (Rectangle)Rectangle to fill.
gradient (Gradient)Gradient.
arc (Arc)Gradient arc spline. Should be in the XY plane.

DrawCircularGradient

#Example
public static void DrawCircularGradient(this BitmapData data, Rectangle rectangle, Gradient gradient, PointF centre, float angle)
Draw a circular gradient into a rectangle.
data (BitmapData)Bitmap to draw onto.
rectangle (Rectangle)Rectangle to fill.
gradient (Gradient)Gradient.
centre (PointF)Centre point of gradient.
angle (float)Gradient zero angle, counter clockwise from positive x-axis.

DrawExpressionGradient

#Example
public static void DrawExpressionGradient(this BitmapData data, Rectangle rectangle, Gradient gradient, Expression expression)
Draw an expression evaluated gradient into a rectangle.
data (BitmapData)Bitmap to draw onto.
rectangle (Rectangle)Rectangle to fill.
gradient (Gradient)Gradient.
expression (Expression)Expression to evaluate. Expression must take x and y variables and resolve to a number.

DrawLinearGradient

#Example
public static void DrawLinearGradient(this BitmapData data, Rectangle rectangle, Gradient gradient, PointF point0, PointF point1)
Draw a linear gradient into a rectangle.
data (BitmapData)Bitmap to draw onto.
rectangle (Rectangle)Rectangle to fill.
gradient (Gradient)Gradient.
point0 (PointF)Start point of gradient.
point1 (PointF)End point of gradient.

DrawRadialGradient

#Example
public static void DrawRadialGradient(this BitmapData data, Rectangle rectangle, Gradient gradient, PointF centre, float innerRadius, float outerRadius)
Draw a radial gradient into a rectangle.
data (BitmapData)Bitmap to draw onto.
rectangle (Rectangle)Rectangle to fill.
gradient (Gradient)Gradient.
centre (PointF)Centre point of gradient.
innerRadius (float)Inner radius of gradient.
outerRadius (float)Outer radius of gradient.

DrawRectangleGradient

#Example
public static void DrawRectangleGradient(this BitmapData data, Rectangle rectangle, Gradient gradient, RectangleF box, float distance0, float distance1)
Draw a rectangle gradient into a rectangle.
data (BitmapData)Bitmap to draw onto.
rectangle (Rectangle)Rectangle to fill.
gradient (Gradient)Gradient.
box (RectangleF)Gradient base rectangle.
distance0 (float)Distance from rectangle where gradient starts.
distance1 (float)Distance from rectangle where gradient ends.

DrawSimplexNoiseGradient

#Example
public static void DrawSimplexNoiseGradient(this BitmapData data, Rectangle rectangle, Gradient gradient)
Draw an expression evaluated gradient into a rectangle.
data (BitmapData)Bitmap to draw onto.
rectangle (Rectangle)Rectangle to fill.
gradient (Gradient)Gradient.

DropShadow

#Example
public static void DropShadow(this BitmapData data, ShadowStyle style, float darkness = 0.35, float decay = 0.95, bool bottomFade = true)
Create a fading and blurring drop shadow directly downwards.
data (BitmapData)Locked bitmap data.
style (BitmapExtensionMethods.ShadowStyle)Shadow styling.
darkness (float = 0.35)Shadow darkness directly underneath opaque pixels.
decay (float = 0.95)Transparency decay as shadow moves downwards.
bottomFade (bool = true)If true, the shadow fades near the bottom of the image.

DuplicateEdgePixels

#Example
public static void DuplicateEdgePixels(this BitmapData data, Rectangle edges)
Duplicate all pixels on the edges rectangle outwards.
data (BitmapData)Bitmap data to modify.
edges (Rectangle)Edges rectangle. Must be fully within the bitmap bounds.

Enlarge

#Example
public static Bitmap Enlarge(this Bitmap bitmap, int factorX, int factorY)
Enlarge a bitmap with integral factors.
bitmap (Bitmap)Bitmap to enlarge.
factorX (int)Scaling factor in X.
factorY (int)Scaling factor in Y.
Enlarged bitmap.

FadeEdges

#Example
public static void FadeEdges(this BitmapData data, int left, int top, int right, int bottom)
Linearly increase the transparency of the edges of the image.
data (BitmapData)Bitmap locked bytes.
left (int)Number of pixel columns along the left edge for fading.
top (int)Number of pixel rows along the top edge for fading.
right (int)Number of pixel columns along the right edge for fading.
bottom (int)Number of pixel rows along the bottom edge for fading.

FadeTransparent

#Example
public static void FadeTransparent(this BitmapData data, float factor)
Multiply all the alpha values with a specific constant.
data (BitmapData)Bitmap to modify.
factor (float)Alpha multiplication factor to use.

FillShape

#Example
public static void FillShape(this BitmapData bitmap, IEnumerable<Curve> shapes, Color fill, bool invert, float edge, float contrast)
Fill the inside of a closed shape with a specific colour.
bitmap (BitmapData)Bitmap data to modify.
shapes (IEnumerable<Curve>)Shapes to fill.
fill (Color)Fill colour.
invert (bool)Invert inside/outside metric.
edge (float)Round edge thickness.
contrast (float)Contrast.

FillShape

#Example
public static void FillShape(this BitmapData bitmap, IEnumerable<Curve> shapes, Color fill, bool invert)
Fill the inside of a closed shape with a specific colour.
bitmap (BitmapData)Bitmap data to modify.
shapes (IEnumerable<Curve>)Shapes to fill.
fill (Color)Fill colour.
invert (bool)Invert inside/outside metric.

FrameEdges

#Example
public static void FrameEdges(this BitmapData data, int depth)
Replace all pixels around the edges of the bitmap with the nearest colour on the interior.
data (BitmapData)Bitmap data to frame.
depth (int)Frame depth.

FromColorArray

#Example
public static void FromColorArray(this BitmapData data, Color[][] buffer, int x0, int x1, int y0, int y1)
Copy the contents of a colour buffer back into a bitmap.
data (BitmapData)Bitmap to copy into.
buffer (Color[][])Colour buffer.
x0 (int)Inclusive left edge of copy domain.
x1 (int)Exclusive right edge of copy domain.
y0 (int)Inclusive top edge of copy domain.
y1 (int)Exclusive bottom edge of copy domain.

FromColorArray

#Example
public static void FromColorArray(this BitmapData data, Color[][] buffer)
Copy the entire contents of a colour buffer back into a bitmap.
data (BitmapData)Bitmap to copy into.
buffer (Color[][])Colour buffer.

LoadImageFromColourAndAlphaFiles

#
public static Bitmap LoadImageFromColourAndAlphaFiles(string colourFile, string alphaFile)
Load an image from a colour file and an alpha file.
colourFile (string)
alphaFile (string)

MakeGreyScale

#Example
public static void MakeGreyScale(this BitmapData data, LuminanceMetric metric, bool retainAlpha, Gradient gradient)
Turn a bitmap into a greyscale represention of itself.
data (BitmapData)Bitmap to modify.
metric (LuminanceMetric)Luminance metric to use.
retainAlpha (bool)If true, alpha values are maintained.
gradient (Gradient)Gradient for luminance mapping. Gradient should be well defined between 0.0 and 1.0.

MakeGreyScale

#Example
public static void MakeGreyScale(this BitmapData data, LuminanceMetric metric, bool retainAlpha)
Turn a bitmap into a greyscale represention of itself.
data (BitmapData)Bitmap to modify.
metric (LuminanceMetric)Luminance metric to use.
retainAlpha (bool)If true, alpha values are maintained.

MakeTransparent

#Example
public static void MakeTransparent(this BitmapData data, float alpha)
Set all the alpha values to a specific constant.
data (BitmapData)Bitmap to modify.
alpha (float)Alpha to use.

MultiplyHsla

#Example
public static void MultiplyHsla(this BitmapData data, float hue, float saturation, float luminance, float alpha)
Multiply all values in a specific channel by a factor.
data (BitmapData)Bitmap to modify.
hue (float)Hue channel multiplication factor.
saturation (float)Saturation channel multiplication factor.
luminance (float)Luminance channel multiplication factor.
alpha (float)Alpha channel multiplication factor.

MultiplyRgba

#Example
public static void MultiplyRgba(this BitmapData data, float red, float green, float blue, float alpha)
Multiply all values in a specific channel by a factor.
data (BitmapData)Bitmap to modify.
red (float)Red channel multiplication factor.
green (float)Green channel multiplication factor.
blue (float)Blue channel multiplication factor.
alpha (float)Alpha channel multiplication factor.

Overlay

#Example
public static void Overlay(this BitmapData target, BitmapData source, Point position, Overlay overlay)
Overlay an image on top of this image.
target (BitmapData)Target image.
source (BitmapData)Overlay image.
position (Point)Position of overlay.
overlay (Overlay)Overlay filter.

PadEdges

#Example
public static Bitmap PadEdges(this Bitmap bitmap, int count, Color colour)
Pad all edges of a bitmap by a specific count.
bitmap (Bitmap)Bitmap to pad.
count (int)Number of pixels to add to all edges.
colour (Color)Padding colour.
Padded bitmap.

PadEdges

#Example
public static Bitmap PadEdges(this Bitmap bitmap, int count)
Pad all edges of a bitmap by a specific count.
bitmap (Bitmap)Bitmap to pad.
count (int)Number of pixels to add to all edges.
Padded bitmap.

PadEdges

#Example
public static Bitmap PadEdges(this Bitmap bitmap, Padding padding, Color colour)
Pad all edges of a bitmap by a specific count.
bitmap (Bitmap)Bitmap to pad.
padding (Padding)Padding dimensions.
colour (Color)Padding colour.
Padded bitmap.

PadEdges

#Example
public static Bitmap PadEdges(this Bitmap bitmap, Padding padding)
Pad all edges of a bitmap by a specific count.
bitmap (Bitmap)Bitmap to pad.
padding (Padding)Padding dimensions.
Padded bitmap.

PaletteDeviation

#Example
public static void PaletteDeviation(this BitmapData data, IEnumerable<Color> palette, ChannelMapping mapping, Gradient gradient)
Map the distances from each pixel to an existing palette.
data (BitmapData)Image data.
palette (IEnumerable<Color>)Palette.
mapping (ChannelMapping)Colour mapping.
gradient (Gradient)Gradient to apply (0.0 = exact match, 1.0=furthest possible distance).

PaletteDeviation

#Example
public static void PaletteDeviation(this BitmapData data, SpatialTree<Color> palette, Gradient gradient)
Map the distances from each pixel to an existing palette.
data (BitmapData)Image data.
palette (SpatialTree<Color>)Palette.
gradient (Gradient)Gradient to apply (0.0 = exact match, 1.0=furthest possible distance).
public static void Place(this BitmapData target, BitmapData source, Point position)
Place another bitmap into this bitmap.
target (BitmapData)Bitmap to insert into.
source (BitmapData)Bitmap to insert.
position (Point)Position (upper left pixel) of placed bitmap.

PrintScreenArea

#
public static Bitmap PrintScreenArea(PointF centre, Size size)
Gets a custom sized portion of the screen underneath the cursor. The cursor location is in the middle.
centre (PointF)
size (Size)
Bitmap under cursor.
public static void Save(this Bitmap bitmap, string path)
Bitmap save process which automatically picks the correct file format.
bitmap (Bitmap)Bitmap to save.
path (string)Path to save to.

SaveImageToColourAndAlphaFiles

#
public static void SaveImageToColourAndAlphaFiles(string imageFile, string colourFile, string alphaFile)
Save a bitmap as a separate colour file and a separate alpha channel file. This is basically used to create jpeg sized images with alpha channels.
imageFile (string)Bitmap to split.
colourFile (string)Colour file path.
alphaFile (string)Alpha file path.

ShowCaseChannel

#Example
public static void ShowCaseChannel(this BitmapData data, Channel channel)
Highlight a specific channel. This is primarily a UI filter, showing the user the salient properties of a specific channel.
data (BitmapData)Bitmap to modify.
channel (Channel)Channel to highlight.

ShowCaseChannel

#Example
public static void ShowCaseChannel(this BitmapData data, LuminanceMetric metric)
Highlight the luminance channel using a specific metric. This is primarily a UI filter, showing the user the salient properties of a specific channel.
data (BitmapData)Bitmap to modify.
metric (LuminanceMetric)Metric to highlight.

StackHorizontal

#Example
public static Bitmap StackHorizontal(this Bitmap bitmap, params Bitmap[] tiles)
Stack a bunch of bitmaps horizontally.
bitmap (Bitmap)First bitmap.
tiles (params Bitmap[])Additional bitmaps to stack.
Stacked bitmap.

StackVertical

#Example
public static Bitmap StackVertical(this Bitmap bitmap, params Bitmap[] tiles)
Stack a bunch of bitmaps vertically.
bitmap (Bitmap)First bitmap.
tiles (params Bitmap[])Additional bitmaps to stack.
Stacked bitmap.

Streak

#Example
public static void Streak(this BitmapData data, StreakDirection direction, int offset)
Streak an image.
data (BitmapData)Bitmap to streak.
direction (BitmapExtensionMethods.StreakDirection)Streaking direction.
offset (int)Streak source offset.

ToColorArray

#Example
public static Color[][] ToColorArray(this BitmapData data)
Convert a bitmap into a jagged colour array.
data (BitmapData)Bitmap to convert.
Jagged array of colours. Each nested array represents a column in the original bitmap.

ToColorSet

#Example
public static SampleSet<Color> ToColorSet(this Bitmap bitmap, int accuracy, bool alpha)
Create a sampling set of all the colours in a bitmap.
bitmap (Bitmap)Bitmap to sample.
accuracy (int)Number of pixels between steps.
alpha (bool)If true, alpha values will be included in the set.
Sampling set.

ToColorSet

#Example
public static SampleSet<Color> ToColorSet(this BitmapData data, int accuracy, bool alpha)
Create a sampling set of all the colours in a bitmap.
data (BitmapData)Bitmap to sample.
accuracy (int)Number of pixels between steps.
alpha (bool)If true, alpha values will be included in the set.
Sampling set.

ToCursor

#Example
public static Cursor ToCursor(this Bitmap bitmap, int targetSize, PointF hotspot)
Convert a bitmap to a cursor.
bitmap (Bitmap)Bitmap to use. Should be square.
targetSize (int)Target size (width and height in pixels).
hotspot (PointF)Hotspot coordinate within [targetSize,targetSize] box.
public static Bitmap Trim(this BitmapData data, int x0, int x1, int y0, int y1)
Cut out a portion of a bitmap.
data (BitmapData)Bitmap to copy from.
x0 (int)Index of first column to include in the copy.
x1 (int)Index of last column to include in the copy.
y0 (int)Index of first row to include in the copy.
y1 (int)Index of last row to include in the copy.
Trimmed bitmap.

TrimEdges

#Example
public static Bitmap TrimEdges(this Bitmap bitmap, Color trimColour, int leaveColumns = 0)
Create a new bitmap which trims all edges if they consist of a solid colour.
bitmap (Bitmap)Bitmap to trim.
trimColour (Color)Colour to cut away.
leaveColumns (int = 0)Number of columns to leave intact anyway.
Trimmed bitmap, or the same bitmap if no trimming was possible.