鼠标移动获取视类图像灰度

来源:互联网 发布:手机摄像头破解软件 编辑:程序博客网 时间:2024/06/08 02:13

    void CPvcamView::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); 
 CScrollView::OnMouseMove(nFlags, point);
}

原创粉丝点击