赞
踩
参考《关于对话框picture控件里画矩形的问题》http://bbs.csdn.net/topics/390772898
void CPcbRegionMatchDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
m_fLButtonDownNotUp = true;
if((point.x<m_picRect.right)&&(point.x>m_picRect.left)&&(point.y<m_picRect.bottom)&&(point.y>m_picRect.top)){
m_chRegionLeftTopPoint = point;
}
CDialogEx::OnLButtonDown(nFlags, point);
}
void CPcbRegionMatchDlg::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
if((point.x<m_picRect.right)&&(point.x>m_picRect.left)&&(point.y<m_picRect.bottom)&&(point.y>m_picRect.top)){
if(m_fLButtonDownNotUp){
//m_drawImg = m_pcbOcr.getImg();
m_cimg.CopyOf(&IplImage(m_drawImg),m_drawImg.channels());
GetDlgItem(IDC_PICTURE)->GetClientRect(&m_picRect); //获取box1客户区
m_cimg.DrawToHDC(m_picHDC,&m_picRect);
m_chRegionRightBottomPoint = point;
CDC *pDC = GetDlgItem(IDC_PICTURE)->GetDC();
CBrush* pOldBrush = (CBrush*)pDC->SelectStockObject(NULL_BRUSH);
CPen* pen = new CPen(PS_SOLID,1,RGB(0,255,0));
CPen* oldPen = pDC->SelectObject(pen);
pDC->Rectangle(CRect(m_chRegionLeftTopPoint,m_chRegionRightBottomPoint));
pDC->SelectObject(pOldBrush);
pDC->SelectObject(oldPen);
delete pen;
}
}
CDialogEx::OnMouseMove(nFlags, point);
}
void CPcbRegionMatchDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
if((point.x<m_picRect.right)&&(point.x>m_picRect.left)&&(point.y<m_picRect.bottom)&&(point.y>m_picRect.top)){
if(m_fLButtonDownNotUp){
m_chRegionRightBottomPoint = point;
//绘制矩形
CDC *pDC = GetDlgItem(IDC_PICTURE)->GetDC();
CBrush* pOldBrush = (CBrush*)pDC->SelectStockObject(NULL_BRUSH);
CPen* pen = new CPen(PS_SOLID,1,RGB(0,255,0));
CPen* oldPen = pDC->SelectObject(pen);
pDC->Rectangle(CRect(m_chRegionLeftTopPoint,m_chRegionRightBottomPoint));
pDC->SelectObject(pOldBrush);
pDC->SelectObject(oldPen);
delete pen;
//矩形区域换算到图像区域
double widthRatio = double(m_drawImg.cols)/m_picRect.Width();
double heightRatio = double(m_drawImg.rows)/m_picRect.Height();
m_subImgRect.x = int(m_chRegionLeftTopPoint.x * widthRatio);
m_subImgRect.y = int(m_chRegionLeftTopPoint.y * heightRatio);
m_subImgRect.width = int((m_chRegionRightBottomPoint.x - m_chRegionLeftTopPoint.x)* widthRatio);
m_subImgRect.height = int((m_chRegionRightBottomPoint.y - m_chRegionLeftTopPoint.y)* heightRatio);
/*Mat subImg = m_drawImg(m_subImgRect);
namedWindow("subImg");
imshow("subImg",subImg);
waitKey();*/
}
}
m_fLButtonDownNotUp = false;
CDialogEx::OnLButtonUp(nFlags, point);
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。