当我滑过轨迹栏时,是否有更好的方法可以平滑地更改图像的色调?我正在做的是获取每个像素的 RGB 值,计算饱和度和亮度,然后将值放入。图像的大小会影响色调更新的速度。Photoshop 的图像色调功能将色调从 0 平滑地更改为 360,这是我想要尝试的。
data = editImage.LockBits(new Rectangle(0, 0, editWidth, editHeight),
ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
byte* dataPtr = (byte*)data.Scan0;
h = trackBar1.Value / 60.0;
D = 1 - Math.Abs((h % 2) - 1);
if (h >= 0 && h < 1)
{
for (int i = 0; i < editHeight; i++)
{
offsetStride = i * data.Stride;
for (int j = 0; j < editWidth; j++)
{
blue = dataPtr[(j * 3) + offsetStride];
green = dataPtr[(j * 3) + offsetStride + 1];
red = dataPtr[(j * 3) + offsetStride + 2];
if (green > blue) max = green;
else max = blue;
if (red > max) max = red;
if (green < blue) min = green;
else min = blue;
if (red < min) min = red;
s = (max == 0) ? 0 : 1d - (1d * min / max);
v = max / 255d;
C = v * s;
X = C * D;
E = v - C;
dataPtr[(j * 3) + offsetStride] = (byte)(min);
dataPtr[(j * 3) + offsetStride + 1] = (byte)((X + E) * 255);
dataPtr[(j * 3) + offsetStride + 2] = (byte)(max);
}
}
}