Adjust image brightness in C#
There are a couple of ways to do this. This method does not use ColorMatrix.
private static System.Drawing.Image _AlterBrightness(System.Drawing.Image bmp, int level)
{
Graphics graphics = Graphics.FromImage(bmp);
if (level == 50)
{
// do nothing
return bmp;
}
else if (level <50)
{
// make it darker
// Work out how much darker
int conversion = 250 - (5 * level);
Pen pDark = new Pen(Color.FromArgb(conversion,0,0,0), bmp.Width*2);
graphics.DrawLine(pDark,0,0,bmp.Width,bmp.Height);
}
else if (level >50)
{
// mark it lighter
// Work out how much lighter.
int conversion = (5 * (level - 50));
Pen pLight = new Pen(Color.FromArgb(conversion,255,255,255), bmp.Width*2);
graphics.DrawLine(pLight,0,0,bmp.Width,bmp.Height);
}
graphics.Save();
graphics.Dispose();
return bmp;
}
