This article describes the method of adjusting contrast of C# images. Share it for your reference. The details are as follows:
//Define the contrast adjustment functionprivate static Bitmap ContrastP(Bitmap a, double 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++) { temp = (int)((p[0] - 127) * v + 127); temp = (temp > 255) ? 255 : temp < 0 ? 0 : temp; p[0] = (byte)temp; p++; } p += stride - * 3; } } (bmpData); return a; }
I hope this article will be helpful to everyone's C# programming.