BitmapExtensionMethods
Extension methods for Eto.Drawing.Bitmap
Methods
Add a constant to all values in HSL channels.
Add a constant to all channel values.
Apply a custom filter delegate to a bitmap.
Parameters:
| data (BitmapData) | Bitmap to modify. |
| filter (Func<Color, Color>) | Filter to apply. |
Blur an image.
Parameters:
| 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. |
Apply a custom blurring curve.
Parameters:
| 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. |
Clear the entire image using a checkerboard pattern.
Parameters:
| data (BitmapData) | Bitmap data accessor. |
| a (Color) | First colour. |
| b (Color) | Second colour. |
| size (int) | Square size. |
Apply colour to half the pixels in an image using a checkerboard pattern.
Parameters:
| data (BitmapData) | Bitmap data accessor. |
| colour (Color) | Colour. |
| size (int) | Square size. |
public static void ClearRectangle(this BitmapData data, Rectangle rectangle, Color color)
Set all pixels within a rectangle to a specific colour.
Parameters:
| data (BitmapData) | 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.
Parameters:
| radius (int) | Radius of curve. |
| profile (BlurProfile) | Profile type to create. |
Returns: Blurring curve.
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.
Parameters:
| 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. |
Returns: Array of colour representing the N most relevant colours in the bitmap.
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.
Parameters:
| 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. |
Returns: Array of colour representing the N most relevant colours in the bitmap.
public static void Dither(this BitmapData data, IEnumerable<Color> palette, DitherAlgorithm algorithm)
Dither an image using a palette.
Parameters:
| data (BitmapData) | Bitmap to dither. |
| palette (IEnumerable<Color>) | Collection of colours in palette. |
| algorithm (DitherAlgorithm) | Dither algorithm to use. |
public static void Dither(this BitmapData data, SpatialTree<Color> palette, DitherAlgorithm algorithm)
Dither an image using a palette.
Parameters:
| data (BitmapData) | Bitmap to dither. |
| palette (SpatialTree<Color>) | Palette stored as spatial tree. |
| algorithm (DitherAlgorithm) | Dither algorithm to use. |
Draw an arc gradient into a rectangle.
Draw a circular gradient into a rectangle.
public static void DrawExpressionGradient(this BitmapData data, Rectangle rectangle, Gradient gradient, Expression expression)
Draw an expression evaluated gradient into a rectangle.
Parameters:
| 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. |
public static void DrawLinearGradient(this BitmapData data, Rectangle rectangle, Gradient gradient, PointF point0, PointF point1)
Draw a linear gradient into a rectangle.
Parameters:
| 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. |
Draw a radial gradient into a rectangle.
Draw a rectangle gradient into a rectangle.
public static void DrawSimplexNoiseGradient(this BitmapData data, Rectangle rectangle, Gradient gradient)
Draw an expression evaluated gradient into a rectangle.
Parameters:
| data (BitmapData) | Bitmap to draw onto. |
| rectangle (Rectangle) | Rectangle to fill. |
| gradient (Gradient) | Gradient. |
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.
Parameters:
| 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. |
public static void DuplicateEdgePixels(this BitmapData data, Rectangle edges)
Duplicate all pixels on the edges rectangle outwards.
Parameters:
| data (BitmapData) | Bitmap data to modify. |
| edges (Rectangle) | Edges rectangle. Must be fully within the bitmap bounds. |
Enlarge a bitmap with integral factors.
Linearly increase the transparency of the edges of the image.
Parameters:
| 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. |
Multiply all the alpha values with a specific constant.
Parameters:
| data (BitmapData) | Bitmap to modify. |
| factor (float) | Alpha multiplication factor to use. |
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.
Parameters:
| 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. |
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.
Parameters:
| bitmap (BitmapData) | Bitmap data to modify. |
| shapes (IEnumerable<Curve>) | Shapes to fill. |
| fill (Color) | Fill colour. |
| invert (bool) | Invert inside/outside metric. |
Replace all pixels around the edges of the bitmap with the nearest colour on the interior.
Parameters:
| data (BitmapData) | Bitmap data to frame. |
| depth (int) | Frame depth. |
Copy the contents of a colour buffer back into a bitmap.
public static void FromColorArray(this BitmapData data, Color[][] buffer)
Copy the entire contents of a colour buffer back into a bitmap.
Parameters:
| data (BitmapData) | Bitmap to copy into. |
| buffer (Color[][]) | Colour buffer. |
LoadImageFromColourAndAlphaFiles
#Load an image from a colour file and an alpha file.
public static void MakeGreyScale(this BitmapData data, LuminanceMetric metric, bool retainAlpha, Gradient gradient)
Turn a bitmap into a greyscale represention of itself.
Parameters:
| 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. |
Turn a bitmap into a greyscale represention of itself.
Parameters:
| data (BitmapData) | Bitmap to modify. |
| metric (LuminanceMetric) | Luminance metric to use. |
| retainAlpha (bool) | If true, alpha values are maintained. |
Set all the alpha values to a specific constant.
Parameters:
| data (BitmapData) | Bitmap to modify. |
| alpha (float) | Alpha to use. |
Multiply all values in a specific channel by a factor.
Multiply all values in a specific channel by a factor.
public static void Overlay(this BitmapData target, BitmapData source, Point position, Overlay overlay)
Overlay an image on top of this image.
Parameters:
| target (BitmapData) | Target image. |
| source (BitmapData) | Overlay image. |
| position (Point) | Position of overlay. |
| overlay (Overlay) | Overlay filter. |
Pad all edges of a bitmap by a specific count.
Parameters:
| bitmap (Bitmap) | Bitmap to pad. |
| count (int) | Number of pixels to add to all edges. |
| colour (Color) | Padding colour. |
Returns: Padded bitmap.
Pad all edges of a bitmap by a specific count.
Parameters:
| bitmap (Bitmap) | Bitmap to pad. |
| count (int) | Number of pixels to add to all edges. |
Returns: Padded bitmap.
public static Bitmap PadEdges(this Bitmap bitmap, Padding padding, Color colour)
Pad all edges of a bitmap by a specific count.
Parameters:
| bitmap (Bitmap) | Bitmap to pad. |
| padding (Padding) | Padding dimensions. |
| colour (Color) | Padding colour. |
Returns: Padded bitmap.
public static Bitmap PadEdges(this Bitmap bitmap, Padding padding)
Pad all edges of a bitmap by a specific count.
Parameters:
| bitmap (Bitmap) | Bitmap to pad. |
| padding (Padding) | Padding dimensions. |
Returns: Padded bitmap.
public static void PaletteDeviation(this BitmapData data, IEnumerable<Color> palette, ChannelMapping mapping, Gradient gradient)
Map the distances from each pixel to an existing palette.
Parameters:
| 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). |
public static void PaletteDeviation(this BitmapData data, SpatialTree<Color> palette, Gradient gradient)
Map the distances from each pixel to an existing palette.
Parameters:
| data (BitmapData) | Image data. |
| palette (SpatialTree<Color>) | Palette. |
| gradient (Gradient) | Gradient to apply (0.0 = exact match, 1.0=furthest possible distance). |
Place another bitmap into this bitmap.
Parameters:
| 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.
Parameters:
| centre (PointF) | |
| size (Size) |
Returns: Bitmap under cursor.
Bitmap save process which automatically picks the correct file format.
Parameters:
| bitmap (Bitmap) | Bitmap to save. |
| path (string) | 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.
Highlight a specific channel. This is primarily a UI filter, showing the user the salient properties of a specific channel.
Parameters:
| data (BitmapData) | Bitmap to modify. |
| channel (Channel) | Channel to highlight. |
Highlight the luminance channel using a specific metric. This is primarily a UI filter, showing the user the salient properties of a specific channel.
Parameters:
| data (BitmapData) | Bitmap to modify. |
| metric (LuminanceMetric) | Metric to highlight. |
public static Bitmap StackHorizontal(this Bitmap bitmap, params Bitmap[] tiles)
Stack a bunch of bitmaps horizontally.
Parameters:
| bitmap (Bitmap) | First bitmap. |
| tiles (params Bitmap[]) | Additional bitmaps to stack. |
Returns: Stacked bitmap.
public static Bitmap StackVertical(this Bitmap bitmap, params Bitmap[] tiles)
Stack a bunch of bitmaps vertically.
Parameters:
| bitmap (Bitmap) | First bitmap. |
| tiles (params Bitmap[]) | Additional bitmaps to stack. |
Returns: Stacked bitmap.
Streak an image.
Parameters:
| data (BitmapData) | Bitmap to streak. |
| direction (BitmapExtensionMethods.StreakDirection) | Streaking direction. |
| offset (int) | Streak source offset. |
public static Color[][] ToColorArray(this BitmapData data)
Convert a bitmap into a jagged colour array.
Parameters:
| data (BitmapData) | Bitmap to convert. |
Returns: Jagged array of colours. Each nested array represents a column in the original bitmap.
Create a sampling set of all the colours in a bitmap.
Create a sampling set of all the colours in a bitmap.
Convert a bitmap to a cursor.
Parameters:
| 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. |
Cut out a portion of a bitmap.
Create a new bitmap which trims all edges if they consist of a solid colour.
Parameters:
| bitmap (Bitmap) | Bitmap to trim. |
| trimColour (Color) | Colour to cut away. |
| leaveColumns (int = 0) | Number of columns to leave intact anyway. |
Returns: Trimmed bitmap, or the same bitmap if no trimming was possible.