public static void Recolor(this LocklessBitmap bitmap, float r, float g, float b) { for (int y = 0; y < bitmap.Height; y++) { for (int x = 0; x < bitmap.Width; x++) { Color pixel = bitmap.GetPixel(x, y); byte rPixel = pixel.R; byte gPixel = pixel.G; byte bPixel = pixel.B; if (r != 0) { rPixel = (byte)Math.Min((1 - r) * pixel.R, 255); } if (g != 0) { gPixel = (byte)Math.Min((1 - g) * pixel.G, 255); } if (b != 0) { bPixel = (byte)Math.Min((1 - b) * pixel.B, 255); } bitmap.SetPixel(x, y, Color.FromArgb(pixel.A, rPixel, gPixel, bPixel)); } } }
public void Copy(LocklessBitmap bitmap, Rectangle area) { for (int y = 0; y < area.Height; y++) { for (int x = 0; x < area.Width; x++) { SetPixel(x + area.X, y + area.Y, bitmap.GetPixel(x, y)); } } }
public static void SetToGrayscale(this LocklessBitmap bitmap) { for (int y = 0; y < bitmap.Height; y++) { for (int x = 0; x < bitmap.Width; x++) { int grayscale = bitmap.GetGrayscale(x, y); bitmap.SetPixel(x, y, Color.FromArgb(bitmap.GetPixel(x, y).A, grayscale, grayscale, grayscale)); } } }
public static void Blacken(this LocklessBitmap bitmap, byte threshold) { for (int y = 0; y < bitmap.Height; y++) { int x = 0; while (x <= bitmap.Width - 1 && bitmap.GetGrayscale(x, y) <= threshold) { bitmap.SetPixel(x, y, Color.FromArgb(bitmap.GetPixel(x, y).A, 0, 0, 0)); x++; } x = bitmap.Width - 1; while (x >= 0 && bitmap.GetGrayscale(x, y) <= threshold) { bitmap.SetPixel(x, y, Color.FromArgb(bitmap.GetPixel(x, y).A, 0, 0, 0)); x--; } } for (int x = 0; x < bitmap.Width; x++) { int y = 0; while (y <= bitmap.Height - 1 && bitmap.GetGrayscale(x, y) <= threshold) { bitmap.SetPixel(x, y, Color.FromArgb(bitmap.GetPixel(x, y).A, 0, 0, 0)); y++; } y = bitmap.Height - 1; while (y >= 0 && bitmap.GetGrayscale(x, y) <= threshold) { bitmap.SetPixel(x, y, Color.FromArgb(bitmap.GetPixel(x, y).A, 0, 0, 0)); y--; } } }