Graphics* myGraphics;
Image image(L"C:\\111.bmp");
myGraphics = Graphics::FromImage(&image);
HDC hdc = myGraphics->GetHDC();
int width = image.GetWidth();
int height = image.GetHeight();
m_nPixelCount = width*height;

int r;
int n=0;
int ab[256] = {0};
for (int i = 0; i <= width; i++)
{
for (int j = 0; j <= height; j++)
{
COLORREF col = ::GetPixel(hdc, i, j);
r = GetRValue(&col);

ab[r]=ab[r]+1;
n++; }
}
CString str ;
str.Format(L"%d", ab[166]);
MessageBox(str);功能是要算出图像每个灰度的个数,但所有都是0,就相当于ab[r]=ab[r]+1没有执行一样,但下面的n++执行了,还是r超过了256,到底什么原因