请问如何取得CDC中每一个象素点的数据.

解决方案 »

  1.   

    COLORREF GetPixel(
      HDC hdc,    // handle to DC
      int nXPos,  // x-coordinate of pixel
      int nYPos   // y-coordinate of pixel
    );
      

  2.   

    问题是nXPos, nYPos这2个参数怎么得到..比我我有一副129*100的图,我怎么取得全的的象素点的数据
      

  3.   

    哦,可以直接从CBitmap对象获得。
      

  4.   

    响应鼠标的函数里有nxpos,nypos,或者getcursorpos函数。
      

  5.   

    用个for循环通过GetPixel把每个象素读入一个数组
    在消息函数里添家相应的代码
    比如onlbuttondown,里边有个参数cpoint point的,就是鼠标在客户区的位置
      

  6.   

    要想达到你的目的,不一定非要在一棵树上吊死,你可以用MatLab来实现,它将输出你所要的数据,然后再将Matlab与VC结合起来岂不是很美吗?
      

  7.   

    循环使用:
    COLORREF GetPixel(
      HDC hdc,    // handle to DC
      int nXPos,  // x-coordinate of pixel
      int nYPos   // y-coordinate of pixel
    );
      

  8.   

    HBITMAP hbmp = (HBITMAP)::LoadImage(AfxGetInstanceHandle(), 
    "你的位图.bmp", IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION|LR_LOADFROMFILE);

    if( hbmp == NULL ) 
    return -1; CBitmap m_bmp;
    m_bmp.Attach( hbmp );
    BITMAP bmp;
    m_bmp.GetBitmap(&bmp); CDC dc;
    CDC memDC;
    memDC.CreateCompatibleDC(&dc);
    memDC.SelectObject(&m_bmp);
    POINT pt;
    COLORREF clr;         for(int i=0; i<bmp.bmHeight; i++)
    {
    for(int j=0; j<bmp.bmWidth; j++)
    {
    pt.x = j;
    pt.y = i;
    clr = memDC.GetPixel(pt);
                      }
              }