概述
c#中Bitmap的颜色是RGB,需要转换为HSV之后进行处理。
xa,ya是饱和度调整的起点坐标,xb,yb是饱和度调整的起点坐标。
trackBar2是饱和度调整的滑动条,把50设为原点。
private Bitmap Baohedu(Bitmap oop, int xa, int xb, int ya, int yb)
{
Bitmap nop;
nop = oop.Clone() as Bitmap;
double degree = trackBar2.Value / 50;
int x, y;
Color pixel;
double R = 0, G = 0, B = 0, H = 0, S = 0, V = 0;
double max = 0, min = 0;
for (x = xa; x < xb; x++)
{
for (y = ya; y < yb; y++)
{
pixel = oop.GetPixel(x, y);
R = (double)pixel.R;
G = (double)pixel.G;
B = (double)pixel.B;
R = R / 100; G = G / 100; B = B / 100;
max = Max(R, G, B);
min = Min(R, G, B);
V = max;
if (max == 0) S = 0;
else S = 1 - (min / max);
if (max == min) H = 0;
else if (max == R && G >= B) H = 60 * ((G - B) / (max - min));
else if (max == R && G < B) H = 60 * ((G - B) / (max - min)) + 360;
else if (max == G) H = 60 * ((B - R) / (max - min)) + 120;
else if (max == B) H = 60 * ((R - G) / (max - min)) + 240;
V = V * 100; S = S * 100; S = S * degree;
if (S >= 100) S = 100;
double C = 0, X = 0, Y = 0, Z = 0;
int i = 0;
S = S / 100.0;
V = V / 100.0;
if (S == 0) R = G = B = V;
else
{
H = H / 60;
i = (int)H;
C = H - i;
X = V * (1.0 - S);
Y = V * (1 - S * C);
Z = V * (1 - S * (1 - C));
switch (i)
{
case 0: R = V; G = Z; B = X; break;
case 1: R = Y; G = V; B = X; break;
case 2: R = X; G = V; B = Z; break;
case 3: R = X; G = Y; B = V; break;
case 4: R = Z; G = X; B = V; break;
case 5: R = V; G = X; B = Y; break;
}
}
R = R * 100; G = G * 100; B = B * 100;
if (G >= 255) G = 255;
if (R >= 255) R = 255;
if (B >= 255) B = 255;
if (G <= 0) G = 0;
if (R <= 0) R = 0;
if (B <= 0) B = 0;
nop.SetPixel(x, y, Color.FromArgb((int)R, (int)G, (int)B));
}
}
return nop;
}
private double Max(double a, double b, double c)
{
double max = 0;
max = a;
if (max < b)
max = b;
if (max < c)
max = c;
return max;
}
private double Min(double a, double b, double c)
{
double min = 0;
min = a;
if (min > b)
min = b;
if (min > c)
min = c;
return min;
}
Easy_Example1.rar_winfrom对比度饱和度亮度调整-图像处理文档类资源-CSDN下载
这里的示例包括了这个功能。
最后
以上就是顺利唇彩为你收集整理的图片饱和度更改,c#,winform的全部内容,希望文章能够帮你解决图片饱和度更改,c#,winform所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复