怎样用VC++实现位图的灰度化

如题所述

CImage img;
img.Load(_T("d:\\sex.bmp"));
COLORREF p;
int r,g,b,avg;
int width=img.GetWidth();
int height=img.GetHeight();
for(int x=0;x<width;x++)
{
    for(int y=0;y<height;y++)
    {
        p=img.GetPixel(x,y);
        r=GetRValue(p);
        g=GetGValue(p);
        b=GetBValue(p);
        avg=(r+g+b)/3;
        img.SetPixelRGB(x,y,avg,avg,avg);
    }
}
img.Draw(GetDC()->m_hDC,CRect(0,0,width,height));

温馨提示:答案为网友推荐,仅供参考
相似回答
大家正在搜