更新时间:2015-12-19 22:29:12浏览次数:1+次
void C油表View::OnGdiFlighting()
{
// TODO: 在此添加命令处理程序代码
this->RedrawWindow();
CDC *pDC = GetDC();
Graphics graphics(pDC->m_hDC);
Bitmap image(L"cos.bmp");
INT Width = image.GetWidth();
INT Height = image.GetHeight();
INT A = Width / 2;
int B = Height / 2;
////Center:图片中心,修改此值会让强光中心发生偏移
CPoint Center(A, B);
///R:强光照射面的半径,即:光晕
int R = 100;
Color colorTemp, color2;
Color color;
graphics.DrawImage(&image, Rect(0, 0, Width, Height));
///依次访问每个像素
for (int x = 0; x < Width; x++)
{
for (int y = 0; y < Height; y++)
{
CPoint tmp(x, y);
/////如果像素位于“光晕”之内
if (fDistance(tmp, Center) < R)
{
image.GetPixel(x, y, &color);
float r, g, b;
////根据该点距离强光中心点的距离,重新计算RGB分量
////220:亮度增加常量,该值越大,光亮度越强
r = color.GetRed() + 220 * (1 - fDistance(tmp, Center) / R);
r = max(0, min(r, 255));
g = color.GetRed() + 220 * (1 - fDistance(tmp, Center) / R);
g = max(0, min(g, 255));
b = color.GetRed() + 220 * (1 - fDistance(tmp, Center) / R);
b = max(0, min(b, 255));
colorTemp.SetValue(color2.MakeARGB(255, r, g, b));
///将增亮后的像素回写到位图
image.SetPixel(x, y, colorTemp);
}
}
///动态绘制滤镜效果图
graphics.DrawImage(&image, Rect(Width, 0, Width, Height));
}
}
效果实现:
相关资讯