图像处理中,怎么方便的同时获取图像的像素值和像素的坐标呢

图像处理中,如何方便的同时获取图像的像素值和像素的坐标呢?
图像处理中,如何方便的同时获取图像的像素值和像素的坐标呢?

------解决方案--------------------
在视类添加OnMouseMove函数,鼠标移动到该像素时会在状态栏显示
void CMyView::OnMouseMove(UINT nFlags, CPoint point) 
{
// TODO: Add your message handler code here and/or call default
CStatusBar *pStatusBar = (CStatusBar *)AfxGetMainWnd()
->GetDescendantWindow(AFX_IDW_STATUS_BAR);//获取状态栏指针
CString str1;
CString str2;
// 计算图像的绝对坐标
CPoint pt = point;
int scroll_x = GetScrollPos(SB_HORZ); // 滚动条已滚过的长度
int scroll_y = GetScrollPos(SB_VERT);
pt.x += scroll_x+1; // 因为图像坐标从0开始,所以最后结果要加1
pt.y += scroll_y+1;

// 读取当前点的颜色
COLORREF color = GetDC()->GetPixel(point); // COLORREF中颜色的排列顺序是BGR
str1.Format( " 坐标: x=%d y=%d ",pt.x,pt.y );
str2.Format( " 灰度值: %d ",GetRValue(color) );
pStatusBar->SetPaneInfo(1,NULL,NULL,130);
pStatusBar->SetPaneText(1,str1);
pStatusBar->SetPaneInfo(2,NULL,NULL,100);
pStatusBar->SetPaneText(2,str2);
CScrollView::OnMouseMove(nFlags, point);
}
------解决方案--------------------
探讨
鼠标在图像中标的点的坐标与通过图像数据区遍历得到的坐标是一致的吧?