C#图片处理之:亮度和对比度的校正 .
2012-02-02 11:04
323 查看
亮度和对比度应该是最常见的处理要求了。就算是N年前9寸黑白电视机也必有这两个旋钮。
亮度调整算法很简单。对每一个像素的RGB值同时加上或减去一个特定的值就可以了。当然由于RGB取值范围都是在[0,255]的,所以要考虑到越界的问题。
public static Bitmap KiLighten(Bitmap b, int degree)
public static Bitmap KiContrast(Bitmap b, int degree)
...{
if (b == null)
...{
return null;
}
if (degree < -100) degree = -100;
if (degree > 100) degree = 100;
try
...{
double pixel = 0;
double contrast = (100.0 + degree) / 100.0;
contrast *= contrast;
int width = b.Width;
int height = b.Height;
BitmapData data = b.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
unsafe
...{
byte* p = (byte*)data.Scan0;
int offset = data.Stride - width * 3;
for (int y = 0; y < height; y++)
...{
for (int x = 0; x < width; x++)
...{
// 处理指定位置像素的对比度
for (int i = 0; i < 3; i++)
...{
pixel = ((p[i] / 255.0 - 0.5) * contrast + 0.5) * 255;
if (pixel < 0) pixel = 0;
if (pixel > 255) pixel = 255;
p[i] = (byte)pixel;
} // i
p += 3;
} // x
p += offset;
} // y
}
b.UnlockBits(data);
return b;
}
catch
...{
return null;
}
} // end of Contrast
需要实例的朋友请到文件中去下载。[图片亮度调整实例代码]
亮度调整算法很简单。对每一个像素的RGB值同时加上或减去一个特定的值就可以了。当然由于RGB取值范围都是在[0,255]的,所以要考虑到越界的问题。
public static Bitmap KiLighten(Bitmap b, int degree)
public static Bitmap KiContrast(Bitmap b, int degree)
...{
if (b == null)
...{
return null;
}
if (degree < -100) degree = -100;
if (degree > 100) degree = 100;
try
...{
double pixel = 0;
double contrast = (100.0 + degree) / 100.0;
contrast *= contrast;
int width = b.Width;
int height = b.Height;
BitmapData data = b.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
unsafe
...{
byte* p = (byte*)data.Scan0;
int offset = data.Stride - width * 3;
for (int y = 0; y < height; y++)
...{
for (int x = 0; x < width; x++)
...{
// 处理指定位置像素的对比度
for (int i = 0; i < 3; i++)
...{
pixel = ((p[i] / 255.0 - 0.5) * contrast + 0.5) * 255;
if (pixel < 0) pixel = 0;
if (pixel > 255) pixel = 255;
p[i] = (byte)pixel;
} // i
p += 3;
} // x
p += offset;
} // y
}
b.UnlockBits(data);
return b;
}
catch
...{
return null;
}
} // end of Contrast
需要实例的朋友请到文件中去下载。[图片亮度调整实例代码]
相关文章推荐
- C#图片处理之:亮度和对比度的校正
- C#图片处理之:亮度和对比度的校正
- C#图片处理之:亮度和对比度的校正
- C#图片处理之:亮度和对比度的校正
- iOS中对图片的处理(对图片进行滤镜处理、调整图片饱和度、亮度、对比度、创建一张实时模糊效果 View (毛玻璃效果)、截取一张 view 生成图片)
- CoreImage 可以用滤镜来处理图片,比如修改饱和度,亮度,对比度等
- iOS有关图片处理的总结 (四)------图片的饱和度,亮度,对比度。
- C#图片处理之:Gamma校正 .
- 学习FotoVision 进行C# colorMatrix 对图片的处理 : 亮度调整 抓屏 翻转 随鼠标画矩形
- 原创 ···DELPHI 图片图形图像处理 PS置换滤镜效果,亮度/对比度,纹理贴图效果
- C#图像处理(各种旋转、改变大小、柔化、锐化、雾化、底片、浮雕、黑白、滤镜效果,滤波,图像截取) 对图片的处理 : 亮度调整 抓屏 翻转 随鼠标画矩形
- C#调整图片亮度和对比度
- iOS有关图片处理 图片的饱和度,亮度,对比度
- 学习FotoVision 进行C# colorMatrix 对图片的处理 : 亮度调整 抓屏 翻转 随鼠标画矩形
- 借用gamma校正的方法来调整图片(灰度)亮度(解决侧光问题)并将其再次保存为RGB图片
- 扭曲图片(验证码)的较正处理C#代码
- C#对图片的几种简单处理
- C#对图片的几种简单处理 [ZT]
- OpenCV自带例子(四)改变一张图片的对比度与亮度
- Win8Metro(C#)数字图像处理--2.5图像亮度调整