The task is to impose on the image of various filters. Those. add noise, ripples to the picture, make it black and white, change the brightness, etc. Surely for such operations there is a ready-made library, but the search only provides various tutorials on the implementation of such filters.

One of the guides wrote a change in brightness ... but why do what is already done and optimized

public static Image ChangeBrightness(Bitmap image, float brightness) { ImageAttributes imageAttributes = new ImageAttributes(); int width = image.Width; int height = image.Height; float[][] colorMatrixElements = { new float[] {brightness, 0, 0, 0, 0}, new float[] {0, brightness, 0, 0, 0}, new float[] {0, 0, brightness, 0, 0}, new float[] {0, 0, 0, 1, 0}, new float[] {0, 0, 0, 0, 1} }; ColorMatrix colorMatrix = new ColorMatrix(colorMatrixElements); imageAttributes.SetColorMatrix( colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); Graphics graphics = Graphics.FromImage(image); graphics.DrawImage(image, new Rectangle(0, 0, width, height), 0, 0, width, height, GraphicsUnit.Pixel, imageAttributes); return image; } 
  • one
    AForge.Imaging - user227049
  • So what's the question? - Alexander Petrov
  • @AlexanderPetrov which ready-made libraries exist for such a task - StriBog

2 answers 2

Yes, of course these things have already been implemented.

I can advise OpenCV. It implements almost all operations that can be done with images. In the original, lib is written in C ++, but if open source implementation in C # is openCvSharp .

The functionality is huge, but specifically for your question, you can look at this sample here .

    I change the brightness so, where the number 128 is mate. expectation:

     double k = 20.0; Bitmap img = (Bitmap)System.Drawing.Image.FromFile(@"E:/bmw.jpg"); bool[,] array = new bool[img.Height, img.Width]; Bitmap bm = new Bitmap(img.Width, img.Height); Color[,] colorM = new Color[img.Height, img.Width]; for (int i = 0; i < img.Height; i++) { for (int j = 0; j < img.Width; j++) { int r = img.GetPixel(j, i).R; int g = img.GetPixel(j, i).G; int b = img.GetPixel(j, i).B; r = (int)(r + k * 128 / 100); g = (int)(g + k * 128 / 100); b = (int)(b + k * 128 / 100); if (r > 255) r = 255; if (g > 255) g = 255; if (b > 255) b = 255; var color = Color.FromArgb(r, g, b); bm.SetPixel(j, i, color); //Console.WriteLine(img.GetPixel(j, i)); } } bm.Save("E://bmw2.jpg");