SoFunction
Updated on 2025-03-06

Methods for adjusting brightness of C# images

This article describes the method of adjusting the brightness of C# images. Share it for your reference. The details are as follows:

//Define digital image processing (brightness adjustment function)private static Bitmap BrightnessP(Bitmap a, int v)
{
  bmpData = (new Rectangle(0, 0, , ), , .Format24bppRgb);
 int bytes =  *  * 3;
 IntPtr ptr = bmpData.Scan0;
 int stride = ;
 unsafe
 {
  byte* p = (byte*)ptr;
  int temp;
  for (int j = 0; j < ; j++)
  {
   for (int i = 0; i <  * 3; i++,p++)
   {
   temp = (int)(p[0] + v);
   temp = (temp > 255) ? 255 : temp < 0 ? 0 : temp;
   p[0] = (byte)temp;
   }
   p += stride -  * 3;
  }
 }
 (bmpData);
 return a;
}

I hope this article will be helpful to everyone's C# programming.