当前位置:C++技术网 > 资讯 > GDI+做木刻滤镜

GDI+做木刻滤镜

更新时间:2015-12-19 00:00:23浏览次数:1+次

分析彩色图片的每个像素点就好了,亮的变暗,暗的变亮。上代码:

void C油表View::OnGdiWood()
{
	// TODO: 在此添加命令处理程序代码
	this->RedrawWindow();
	CDC* pDC = GetDC();
	Graphics graphics(pDC->m_hDC);
	Bitmap image(L"cos.bmp");
	int Width = image.GetWidth();
	INT Height = image.GetHeight();
	Color colorTemp, color2;
	Color color;
	graphics.DrawImage(&image, Rect(0, 0, Width, Height));
	int tmp;
	for (int i = 0; i < Width; i++)
	{
		for (int j = 0; j < Height; j++)
		{
			image.GetPixel(i, j, &color);
			int avg;
			avg = (color.GetRed() + color.GetGreen() + color.GetBlue()) / 3;
			if (avg > 128)
			{
				tmp = 255;
			}
			else
			{
				tmp = 0;
			}
			colorTemp.SetValue(color2.MakeARGB(255, tmp,tmp,tmp));
			image.SetPixel(i, j, colorTemp);
		}
		graphics.DrawImage(&image, Rect(Width, 0, Width, Height));
	}
}
代码实现: