当前位置:C++技术网 > 资讯 > 图像偏差的伽马校正

图像偏差的伽马校正

更新时间:2015-11-29 15:56:12浏览次数:1+次

不同的计算机对同一幅图片的显示结果可能不一样(如在MAV和PC两个系列的计算机中),尤其是色彩信息。在计算机系统中,由于显卡或者是显示器的原因,会出现实际输出图像在亮度上有偏差的情况,而Gamma校正就是在通过一定的方法来校正图像的这种偏差方法。一般情况下,当Gamma校正值大于1时,图像的高光部分被压缩而暗调部分被扩展;当Gamma校正值小于1时,图像的高光部分被扩展而暗调部分被压缩,Gamma校正一般用于平滑的扩展暗条的细节。如果想让数字图片在不同的计算机中都能够达到同一显示效果,必须通过软件进行Gamma设置。
Gammma校正是GDI+支持的新功能。对于路径渐变画刷的Gamma校正,可以通过PathGradientBrush类的成员函数SetGammaCorrection(设置伽马校正)来完成。默认情况下,路径渐变画刷的Gamma校正功能是被禁用的。

GDI+程序之前的一些必备代码,我就不说了,请你看看之前的GDI+文章。我们在《多彩色的金字塔》工程的菜单项下的子菜单项

新建一个子菜单项“路径的伽马校正”。并建立消息响应:

void CPathBrushCenterView::OnBrushpathusinggamma()
{
	// TODO:  在此添加命令处理程序代码
	Graphics graphics(this->m_hWnd);
	this->RedrawWindow();
	//////定义五角的边线坐标
	Point points[] = {
		Point(75, 0), Point(100, 50),
		Point(150, 50), Point(112, 75),
		Point(150, 150), Point(75, 100),
		Point(0, 150), Point(37, 75),
		Point(0, 50), Point(50, 50)
	};
	/////构造路径
	GraphicsPath path;
	path.AddLines(points, 10);
	//////由路径到画刷
	PathGradientBrush pthGrBrush(&path);
	/////中心色
	pthGrBrush.SetCenterColor(Color(255, 255, 0, 0));
	//////边界色
	Color colors[] = {
		Color(255, 0, 0, 0), Color(255, 0, 255, 0),
		Color(255, 0, 0, 255), Color(255, 255, 255, 255),
		Color(255, 0, 0, 0), Color(255, 0, 255, 0),
		Color(255, 0, 0, 255), Color(255, 255, 255, 255),
		Color(255, 0, 0, 0), Color(255, 0, 255, 0)
	};
	int count = 10;
	pthGrBrush.SetSurroundColors(colors, &count);
	///////不使用Gamma校正填充目标区域
	graphics.FillPath(&pthGrBrush, &path);
	///////启用Gamma校正
	pthGrBrush.SetGammaCorrection(TRUE);
	/////绘图平面水平移动200个像素
	graphics.TranslateTransform(200, 0);
	graphics.FillPath(&pthGrBrush, &path);
}
代码实现:

相比较第一个图片,第二个更亮色些,这就是伽马校正的效果。你要不要试试?