求高手赐程序实现:将一幅位图逐个象素进行扫描且纪录其坐标极其灰度的vc程序?拜谢!

解决方案 »

  1.   

    看看这个char *pArray = new char [nWidth * nHeight];

        int lLineBytes= WIDTHBYTES(nWidth);
    int temp;
    int k=0;
    for(int i=0;i<nWidth;i++)
    {
    for(int j=0;j<nHeight;j++)
    {
    temp =(unsigned char)(*((char *)lpDIBBits+lLineBytes*(nHeight-1-i)+j));//lpDIBBits没定义,应该是指向数据区域吧
      if(temp==0) pArray[k]='0';
        else if (temp==255) pArray[k]='1';
      else pArray[k]='2';//2用来表示图像中有不是黑和白的颜色
    k++;
             }
        }
        CFile file2;
    file2.Open("textout.txt",CFile::modeCreate | CFile::modeWrite);
    file2.Write( pArray, nWidth * nHeight);//
    file2.Close();
    delete []pArray;
    return TRUE;
    }
      

  2.   

    如果图是彩色的话,就读取出它的每个象素的R,G,B值, Y=0.3×R+0.59×G+0.11×B;就可以求出灰度值了。