/// <summary> /// Sets the color of the pixel using an extra alpha value and a precalculated index (faster). /// For best performance this method should not be used in iterative real-time scenarios. Implement the code directly inside a loop. /// </summary> /// <param name="bmp">The WriteableBitmap.</param> /// <param name="index">The coordinate index.</param> /// <param name="a">The alpha value of the color.</param> /// <param name="color">The color.</param> public static void SetPixeli(this BitmapBuffer bmp, int index, byte a, ColorInt color) { using (BitmapContext context = bmp.GetBitmapContext()) { context.Pixels[index] = color.ToPreMultAlphaColor(); } }
/// <summary> /// Sets the color of the pixel. /// For best performance this method should not be used in iterative real-time scenarios. Implement the code directly inside a loop. /// </summary> /// <param name="bmp">The WriteableBitmap.</param> /// <param name="x">The x coordinate (row).</param> /// <param name="y">The y coordinate (column).</param> /// <param name="color">The color.</param> public static void SetPixel(this BitmapBuffer bmp, int x, int y, ColorInt color) { using (BitmapContext context = bmp.GetBitmapContext()) { context.Pixels[y * context.Width + x] = color.ToPreMultAlphaColor(); } }
public static void Clear(this BitmapContext context, ColorInt color) { int colr = color.ToPreMultAlphaColor(); int[] pixels = context.Pixels; int w = context.Width; int h = context.Height; int len = w * ARGB_SIZE; // Fill first line for (int x = 0; x < w; x++) { pixels[x] = colr; } // Copy first line int blockHeight = 1; int y = 1; while (y < h) { BitmapContext.BlockCopy(context, 0, context, y * len, blockHeight * len); y += blockHeight; blockHeight = Math.Min(2 * blockHeight, h - y); } }
/// <summary> /// Sets the color of the pixel using an extra alpha value. /// For best performance this method should not be used in iterative real-time scenarios. Implement the code directly inside a loop. /// </summary> /// <param name="bmp">The WriteableBitmap.</param> /// <param name="x">The x coordinate (row).</param> /// <param name="y">The y coordinate (column).</param> /// <param name="a">The alpha value of the color.</param> /// <param name="color">The color.</param> public static void SetPixel(this BitmapBuffer bmp, int x, int y, byte a, ColorInt color) { using (BitmapContext context = bmp.GetBitmapContext()) { // Add one to use mul and cheap bit shift for multiplicaltion context.Pixels[y * context.Width + x] = color.ToPreMultAlphaColor(); } }
/// <summary> /// Draws a colored line by connecting two points using the Bresenham algorithm. /// </summary> /// <param name="bmp">The WriteableBitmap.</param> /// <param name="x1">The x-coordinate of the start point.</param> /// <param name="y1">The y-coordinate of the start point.</param> /// <param name="x2">The x-coordinate of the end point.</param> /// <param name="y2">The y-coordinate of the end point.</param> /// <param name="color">The color for the line.</param> /// <param name="clipRect">The region in the image to restrict drawing to.</param> public static void DrawLineBresenham(this BitmapBuffer bmp, int x1, int y1, int x2, int y2, ColorInt color, RectD?clipRect = null) { bmp.DrawLineBresenham(x1, y1, x2, y2, color.ToPreMultAlphaColor(), clipRect); }
/// <summary> /// Draws an anti-aliased line with a desired stroke thickness /// <param name="bmp">The WriteableBitmap.</param> /// <param name="x1">The x-coordinate of the start point.</param> /// <param name="y1">The y-coordinate of the start point.</param> /// <param name="x2">The x-coordinate of the end point.</param> /// <param name="y2">The y-coordinate of the end point.</param> /// <param name="color">The color for the line.</param> /// <param name="strokeThickness">The stroke thickness of the line.</param> /// </summary> public static void DrawLineAa(this BitmapBuffer bmp, int x1, int y1, int x2, int y2, ColorInt color, int strokeThickness, RectD?clipRect = null) { using (BitmapContext context = bmp.GetBitmapContext()) { AAWidthLine(bmp.PixelWidth, bmp.PixelHeight, context, x1, y1, x2, y2, strokeThickness, color.ToPreMultAlphaColor(), clipRect); } }
/// <summary> /// Draws an anti-aliased line with a desired stroke thickness /// <param name="context">The context containing the pixels as int RGBA value.</param> /// <param name="x1">The x-coordinate of the start point.</param> /// <param name="y1">The y-coordinate of the start point.</param> /// <param name="x2">The x-coordinate of the end point.</param> /// <param name="y2">The y-coordinate of the end point.</param> /// <param name="color">The color for the line.</param> /// <param name="strokeThickness">The stroke thickness of the line.</param> /// </summary> public static void DrawLineAa(BitmapContext context, int pixelWidth, int pixelHeight, int x1, int y1, int x2, int y2, ColorInt color, int strokeThickness, RectD?clipRect = null) { AAWidthLine(pixelWidth, pixelHeight, context, x1, y1, x2, y2, strokeThickness, color.ToPreMultAlphaColor(), clipRect); }
/// <summary> /// Draws a cubic Beziér spline defined by start, end and two control points. /// </summary> /// <param name="bmp">The WriteableBitmap.</param> /// <param name="x1">The x-coordinate of the start point.</param> /// <param name="y1">The y-coordinate of the start point.</param> /// <param name="cx1">The x-coordinate of the 1st control point.</param> /// <param name="cy1">The y-coordinate of the 1st control point.</param> /// <param name="cx2">The x-coordinate of the 2nd control point.</param> /// <param name="cy2">The y-coordinate of the 2nd control point.</param> /// <param name="x2">The x-coordinate of the end point.</param> /// <param name="y2">The y-coordinate of the end point.</param> /// <param name="color">The color.</param> public static void DrawBezier(this BitmapBuffer bmp, int x1, int y1, int cx1, int cy1, int cx2, int cy2, int x2, int y2, ColorInt color) { bmp.DrawBezier(x1, y1, cx1, cy1, cx2, cy2, x2, y2, color.ToPreMultAlphaColor()); }
/// <summary> /// Draws a closed Cardinal spline (cubic) defined by a point collection. /// The cardinal spline passes through each point in the collection. /// </summary> /// <param name="bmp">The WriteableBitmap.</param> /// <param name="points">The points for the curve in x and y pairs, therefore the array is interpreted as (x1, y1, x2, y2, x3, y3, x4, y4, x1, x2 ..., xn, yn).</param> /// <param name="tension">The tension of the curve defines the shape. Usually between 0 and 1. 0 would be a straight line.</param> /// <param name="color">The color for the spline.</param> public static void DrawCurveClosed(this BitmapBuffer bmp, int[] points, float tension, ColorInt color) { bmp.DrawCurveClosed(points, tension, color.ToPreMultAlphaColor()); }
/// <summary> /// Draws a series of cubic Beziér splines each defined by start, end and two control points. /// The ending point of the previous curve is used as starting point for the next. /// Therefore the initial curve needs four points and the subsequent 3 (2 control and 1 end point). /// </summary> /// <param name="bmp">The WriteableBitmap.</param> /// <param name="points">The points for the curve in x and y pairs, therefore the array is interpreted as (x1, y1, cx1, cy1, cx2, cy2, x2, y2, cx3, cx4 ..., xn, yn).</param> /// <param name="color">The color for the spline.</param> public static void DrawBeziers(this BitmapBuffer bmp, int[] points, ColorInt color) { bmp.DrawBeziers(points, color.ToPreMultAlphaColor()); }