} // end of Contrast /// <summary> /// 按指定的色调、饱和度、亮度对图像进行调整 /// </summary> /// <param name="b">位图流</param> /// <param name="hue">色调[-180, 180]</param> /// <param name="saturation">饱和度[-1, 1]</param> /// <param name="luminance">亮度[-1, 1]</param> /// <returns></returns> public Bitmap AdjustHsl(Bitmap b, float hue, float saturation, float luminance) { if (hue < -180.0f) { hue = -180.0f; } if (hue > 180.0f) { hue = 180f; } if (saturation < -1.0f) { saturation = -1.0f; } if (saturation > 1.0f) { saturation = 1.0f; } if (luminance < -1.0f) { luminance = -1.0f; } if (luminance > 1.0f) { luminance = 1.0f; } int width = b.Width; int height = b.Height; Bitmap dstImage = new Bitmap(width, height, b.PixelFormat); BitmapData data = b.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); unsafe { byte *p = (byte *)data.Scan0; int offset = data.Stride - width * BPP; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { HSL hsl = HSL.FromRgb(p[2], p[1], p[0]); hsl.Hue += hue; hsl.Saturation += saturation; hsl.Luminance += luminance; p[0] = hsl.GetBlue(); p[1] = hsl.GetGreen(); p[2] = hsl.GetRed(); p += BPP; } // x p += offset; } // y } b.UnlockBits(data); return(b); } // end of AdjustHsl