I need to reduce the brightness of the picture using c#. After some analysis i have found one solution to reduce the brightness of the image by adjusting its each pixel color RGB values. Please find the codes from below:
Bitmap bmp = new Bitmap(Picture);
Reduce the picture color brightness
for (int i = 0; i < bmp.Width; i++)
{
for (int j = 0; j < bmp.Height; j++)
{
Color color = bmp.GetPixel(i, j);
color = ChangeColorBrightness(color, 0.80f);
bmp.SetPixel(i, j, color);
}
}
Method to reduce the RGB values of particular color:
private Color ChangeColorBrightness(Color color, float correctionFactor)
{
float red = (float)color.R;
float green = (float)color.G;
float blue = (float)color.B;
if (correctionFactor < 0)
{
correctionFactor = 1 + correctionFactor;
red *= correctionFactor;
green *= correctionFactor;
blue *= correctionFactor;
}
else
{
red = (255 - red) * correctionFactor + red;
green = (255 - green) * correctionFactor + green;
blue = (255 - blue) * correctionFactor + blue;
}
return Color.FromArgb(color.A, (int)red, (int)green, (int)blue);
}
This codes are working fine for my requirement but it will takes such amount of time when i am executing huge number of images with larger width and height. Is there any other possibilities to achieve this requirement?