void MyTestDialog::DrawPicToHDC(cv::Mat& img, UINT ID) { //清空 CStatic* pStatic = (CStatic*)GetDlgItem(ID); pStatic->SetBitmap(NULL); CRect rect; pStatic->GetClientRect(&rect); pStatic->GetDC()->FillSolidRect(rect.left ,rect.top ,rect.Width(),rect.Height(), RGB(240, 240, 240)); //// CDC* pDC = GetDlgItem(ID)->GetDC(); HDC hDC = pDC->GetSafeHdc(); //调整大小 //////// float widthRatio = (float)rect.Width() / img.cols; float heightRatio = (float)rect.Height() / img.rows; float resRatio = widthRatio < heightRatio ? widthRatio: heightRatio; int resWidth = img.cols * resRatio; int resHeight = img.rows * resRatio; cv::resize(img, img, cv::Size(resWidth, resHeight)); CRect drawRect; drawRect.SetRect(rect.TopLeft().x, rect.TopLeft().y, rect.TopLeft().x + img.cols - 1, rect.TopLeft().y + img.rows - 1); /////// IplImage* tmpimg = &img.operator IplImage(); CvvImage iimg; iimg.CopyOf(tmpimg); iimg.DrawToHDC(hDC, &drawRect); ReleaseDC(pDC); iimg.Destroy(); }
void CMainFrame::UpdateCursorInfoStatus() { CStatic* pDrawingArea = (CStatic*)m_pView->GetDlgItem(IDC_IMAGEAREA); if (pDrawingArea == NULL) { return; } CString status; int x,y=0; m_pView->GetPixelPositionFromImage(&x,&y); CPoint dcPoint; CDC* pDC = pDrawingArea->GetDC(); // Fix for Bug 20448 if(pDC == NULL) { return; } HDC hdc = pDC->GetSafeHdc(); if(hdc == NULL) { return; } GetCursorPos(&dcPoint); pDrawingArea->ScreenToClient(&dcPoint); COLORREF cr = pDC->GetPixel( dcPoint ); m_pView->ReleaseDC( pDC ); if( this == GetActiveWindow() && x != -1 && y != -1 ) { status.Format( "Cursor: (%d,%d) | RGB: (%u,%u,%u)", x, y, cr & 0xFF, (cr & 0xFF00) >> 8, (cr & 0xFF0000) >> 16 ); }