BitmapExtensionMethods

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

Methods

AddHsla

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

AddRgba

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

ApplyFilterDelegate

#Example
Apply a custom filter delegate to a bitmap.
public static void ApplyFilterDelegate(
this BitmapData
data,
Bitmap to modify.
Func<Color, Color>
filter
Filter to apply.
)
Blur an image.
public static void Blur(
this BitmapData
data,
Bitmap to blur.
BlurProfile
profile,
Blurring profile to use.
x,
Horizontal blurring radius.
y,
Vertical blurring radius.
iterations
Number of successive blurring operations to perform.
)
Apply a custom blurring curve.
public static void Blur(
this BitmapData
data,
Bitmap data to operate on.
xProfile,
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,
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
Number of blurring iterations to run.
)

ClearCheckerBoard

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

ClearCheckerBoard

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

ClearRectangle

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

CreateBlurProfile

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

CreatePalette

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

CreatePalette

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

Dither

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

Dither

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

DrawArcGradient

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

DrawCircularGradient

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

DrawExpressionGradient

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

DrawLinearGradient

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

DrawRadialGradient

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

DrawRectangleGradient

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

DrawSimplexNoiseGradient

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

DropShadow

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

DuplicateEdgePixels

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

Enlarge

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

FadeEdges

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

FadeTransparent

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

FillShape

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

FillShape

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

FrameEdges

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

FromColorArray

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

FromColorArray

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

LoadImageFromColourAndAlphaFiles

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

MakeGreyScale

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

MakeGreyScale

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

MakeTransparent

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

MultiplyHsla

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

MultiplyRgba

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

Overlay

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

PadEdges

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

PadEdges

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

PadEdges

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

PadEdges

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

PaletteDeviation

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

PaletteDeviation

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

PrintScreenArea

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

SaveImageToColourAndAlphaFiles

#
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.
public static void SaveImageToColourAndAlphaFiles(
imageFile,
Bitmap to split.
colourFile,
Colour file path.
alphaFile
Alpha file path.
)

ShowCaseChannel

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

ShowCaseChannel

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

StackHorizontal

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

StackVertical

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

Streak

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

ToColorArray

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

ToColorSet

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

ToColorSet

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

ToCursor

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

TrimEdges

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