得到当前显示器显示的图象上某个座标的颜色,并判断是什么颜色。
帮帮忙。给出源码者分儿多多。谢谢。

解决方案 »

  1.   

    COLORREF GetPixel( int x, int y ) const;COLORREF:   0x00bbggrr
      

  2.   

    可以看看这个例子:
    http://www.vckbase.com/document/viewdoc.asp?id=403
      

  3.   

    GetPixel参数是逻辑坐标,如果要得到当前显示器显示的图象上某个座标的颜色,还要转换成屏幕坐标,用CDC::LPtoDP函数即可
      

  4.   

    AGREE chb2000() 
    --------------------------------------------
    OnTimer:CPoint pt;
    GetCursorPos(&pt);HDC hDC = ::GetDC(NULL);
    COLORREF clr = ::GetPixel(hDC, pt.x, pt.y);
    int nR = GetRValue(clr); //Red
    int nG = GetGValue(clr); //Green
    int nB = GetBValue(clr); //BlueCOLORREF yourColor
    if (yourColor==clr)
    ...
      

  5.   

    首先,要获得整个屏幕的DC,用hScrdc=GetDC(0)就行了。
    然后,调用clr=GetPixel(hScrdc,x,y),就可以获得指定位置(x,y)处的RGB颜色
    再用GetRValue(clr),GetGValure(clr),GetBValue(clr)分别获得R,G,B值。要想获得屏幕上任意矩形区域中的图片,可以用BitBlt()函数。
      

  6.   

    我这有整个颜色选择框的源码。下面是你想要的。void CToolColorSelect::OnLButtonDown(UINT nFlags, CPoint point) 
    {
    // TODO: Add your message handler code here and/or call default
    CRect rc;
    GetDlgItem( IDC_STATIC_PALETTE )->GetWindowRect( &rc );
    ScreenToClient( &rc );
    if( rc.PtInRect( point ) )
    {
    CClientDC dc(this);
        UpdateColor( dc.GetPixel( point ) );//得到颜色的就是这一句
         }
    CInitDialogBar::OnLButtonDown(nFlags, point);
    }void CToolColorSelect::UpdateColor( COLORREF dwColor )
    {
    m_btnColor.SetColor( dwColor );
    m_nRed = GetRValue( dwColor );
    m_nGreen = GetGValue( dwColor );
    m_nBlue = GetBValue( dwColor );
    UpdateData( FALSE ); ((CSliderCtrl*)GetDlgItem( IDC_SLIDER_VALUER ))->SetPos(m_nRed);
    ((CSliderCtrl*)GetDlgItem( IDC_SLIDER_VALUEG ))->SetPos(m_nGreen);
    ((CSliderCtrl*)GetDlgItem( IDC_SLIDER_VALUEB ))->SetPos(m_nBlue); GlobalPenSet  * pPenSet;
    pPenSet=((CPatternDesignCADApp *)AfxGetApp())->GetGlobalPenSetPtr();  
    if(dwColor==SYS_COLOR_WHITE)
    dwColor=RGB(254,254,254);
    if(dwColor==SYS_COLOR_BLACK)
    dwColor=RGB(1,1,1);
    pPenSet->SetPenColor(dwColor); 
    }
      

  7.   

    看你用什么DC了,什么DC提取什么颜色!!!Understand???
      

  8.   

    BYTE *ptr;
    int nLineLen;
        BITMAPINFOHEADER bi; CDibDoc* pDoc = GetDocument();
    HDIB hdib = pDoc->GetHDIB();
    if (hdib == NULL)
    return;// ClientToDoc(lgcPoint); //当前图象中获得数据
        DibInfo (hdib, &bi);
    nWidth = (int)bi.biWidth;
    nHeight = (int)bi.biHeight; if(bi.biBitCount != 24) //只能处理24位图像
    return ;

    ptr = (BYTE *)GlobalLock(hdib);

    ptr += (DWORD)bi.biSize + (DWORD)PaletteSize((LPSTR)&bi);

    //每行数据的字节数
    int zhang1 = 1;
    zhang1 = ( nWidth * 3 + 3 ) / 4 ;
    nLineLen = zhang1 * 4; for(int y = 0 ; y < nHeight ; y++)
    for(int x = 0 ; x < nWidth ; x++)
    {
    int B = *(ptr + (DWORD)(nHeight - y - 1) * nLineLen + x*3);
    int G = *(ptr + (DWORD)(nHeight - y - 1) * nLineLen + x*3+1);
    int R = *(ptr + (DWORD)(nHeight - y - 1) * nLineLen + x*3+2); bmp_color_r[y][x] = R;
    bmp_color_b[y][x] = B;
    bmp_color_g[y][x] = G; pellet_label[y][x] = 0;
    }看看吧,是处理24位的