BOOL CStaffSetDlg::ShowPhoto(const CString& strPhotoPath, CWnd* pWnd) { POSITION pos=m_ListCtr_Staff.GetFirstSelectedItemPosition(); int index=m_ListCtr_Staff.GetNextSelectedItem(pos); SLZStaff staffinfo=m_List_StaffInfo.GetAt(m_List_StaffInfo.FindIndex(index)); CStatic* picPhoto = (CStatic*)pWnd; CDC* pDC = picPhoto->GetWindowDC(); CRect rect; picPhoto->GetClientRect(&rect); CImage img; if(strPhotoPath.IsEmpty()) { pDC->SelectStockObject(GRAY_BRUSH); pDC->FillRect( &rect, pDC->GetCurrentBrush()); UpdateData(FALSE); return FALSE; } HRESULT hResult = img.Load(strPhotoPath); if(FAILED(hResult)) { MessageBox(_T("图片路径错误,导入失败")); staffinfo.SetStaffPhoto(_T("")); m_ListCtr_Staff.SetItemText(index,4,_T("未配置")); m_List_StaffInfo.GetAt(m_List_StaffInfo.FindIndex(index))=staffinfo; return FALSE; } pDC->SetStretchBltMode(STRETCH_HALFTONE); img.Draw(pDC->m_hDC, 0, 0, rect.Width(), rect.Height(), 0, 0, img.GetWidth(), img.GetHeight()); //把图片填充在控件中 return TRUE; }
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 MyTestDialog::drawpic(IplImage* img, unsigned int id) { BYTE *g_pBits; HDC g_hMemDC; HBITMAP g_hBmp, g_hOldBmp; CDC *pDC; CStatic *pic; int width, height; CRect rect; pDC = GetDlgItem(id)->GetDC(); pic = (CStatic*)GetDlgItem(id); pic->GetClientRect(&rect); width = rect.Width(); height = rect.Height(); g_hMemDC = ::CreateCompatibleDC(pDC->m_hDC);//创建兼容DC BYTE bmibuf[sizeof(BITMAPINFO)+256 * sizeof(RGBQUAD)]; memset(bmibuf, 0, sizeof(bmibuf)); BITMAPINFO *pbmi = (BITMAPINFO*)bmibuf; pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); pbmi->bmiHeader.biWidth = img->width; pbmi->bmiHeader.biHeight = img->height; pbmi->bmiHeader.biPlanes = 1; pbmi->bmiHeader.biBitCount = 24; pbmi->bmiHeader.biCompression = BI_RGB; g_hBmp = ::CreateDIBSection(g_hMemDC, pbmi, DIB_RGB_COLORS, (void**)&g_pBits, 0, 0);//创建应用程序可以直接写入的、与设备无关的位图(DIB) g_hOldBmp = (HBITMAP)::SelectObject(g_hMemDC, g_hBmp);//复原兼容DC数据 BitBlt(g_hMemDC, 0, 0, width, height, pDC->m_hDC, 0, 0, SRCCOPY); //修改图像内容:g_pBits int l_width = WIDTHBYTES(img->width* pbmi->bmiHeader.biBitCount); for (int row = 0; row < img->height; row++) memcpy(&g_pBits[row*l_width], &img->imageData[ (img->height - row - 1)*l_width], l_width); TransparentBlt(pDC->m_hDC, 0, 0, width, height, g_hMemDC, 0, 0, img->width, img->height, RGB(0, 0, 0)); SelectObject(g_hMemDC, g_hOldBmp); //释放内存资源 ReleaseDC(pDC); DeleteDC(g_hMemDC); DeleteObject(pic); DeleteObject(g_hBmp); DeleteObject(g_hOldBmp); }
void CMyPage2::CurrentFillColor() { UINT nRed, nGreen, nBlue; nRed = GetDlgItemInt(IDC_RED); nGreen = GetDlgItemInt(IDC_GREEN); nBlue = GetDlgItemInt(IDC_BLUE); COLORREF color = RGB(nRed, nGreen, nBlue); // 현재 색상 CRect rc; CStatic* pFrame = (CStatic*)GetDlgItem(IDC_COLOR_SHOW); pFrame->GetClientRect(rc); CClientDC dc(pFrame); CBrush br(color); CBrush* pOld = dc.SelectObject(&br); dc.FillRect(rc, &br); // 현재 색상으로 사각형을 채운다. dc.SelectObject(pOld); }
//********************************************************************** void CBCGPRibbonCustomizeRibbonPage::CreateRibbonTree(CStatic& wndPlaceHolder, CBCGPRibbonTreeCtrl& wndTree) { CRect rectGrid; wndPlaceHolder.GetClientRect (&rectGrid); wndPlaceHolder.MapWindowPoints (this, &rectGrid); #ifndef BCGP_EXCLUDE_GRID_CTRL wndTree.Create (WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER, rectGrid, this, (UINT)-1); wndTree.EnableColumnAutoSize (TRUE); wndTree.SetSingleSel (); wndTree.EnableGroupByBox (FALSE); wndTree.SetReadOnly (); wndTree.SetWholeRowSel (); wndTree.EnableHeader (FALSE, 0); wndTree.EnableGridLines(FALSE); wndTree.SetRowMarker(FALSE); // Set grid tab order (first): wndTree.SetWindowPos (&CWnd::wndTop, -1, -1, -1, -1, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); // Set grid colors CBCGPGridColors colors; colors.m_LeftOffsetColors.m_clrBackground = globalData.clrWindow; colors.m_SelColors.m_clrBackground = ::GetSysColor(COLOR_HIGHLIGHT); colors.m_SelColors.m_clrText = ::GetSysColor(COLOR_HIGHLIGHTTEXT); colors.m_SelColorsInactive.m_clrBackground = ::GetSysColor(COLOR_BTNFACE); colors.m_SelColorsInactive.m_clrText = ::GetSysColor(COLOR_BTNTEXT); wndTree.SetColorTheme (colors); wndTree.InsertColumn (0, _T("Name"), 80); #else wndTree.Create(_T("Please un-comment BCGP_EXCLUDE_GRID_CTRL in BCGCBProConfig.h"), WS_CHILD | WS_VISIBLE | WS_BORDER, rectGrid, this); wndTree.SetFont(GetFont()); #endif }
void MyTestDialog::DrawPicToHDC(IplImage* img, UINT ID) { //清空 CStatic* pStatic = (CStatic*)GetDlgItem(ID); //pStatic->SetBitmap(NULL); CDC* pDC = GetDlgItem(ID)->GetDC(); CRect rect; pStatic->GetClientRect(&rect); //pStatic->GetDC()->FillSolidRect(rect.left ,rect.top ,rect.Width(),rect.Height(), RGB(240, 240, 240)); //// HDC hDc = pDC->GetSafeHdc(); //CRect rect; //GetDlgItem(ID)->GetClientRect(&rect); float widthRatio = (float)rect.Width() / img->width; float heightRatio = (float)rect.Height() / img->height; float resRatio = widthRatio < heightRatio ? widthRatio: heightRatio; int resWidth = img->width * resRatio; int resHeight = img->height * resRatio; IplImage* img2=cvCreateImage(cvSize(resWidth, resHeight),img->depth, img->nChannels); cvResize(img, img2, CV_INTER_NN); img = img2; CvvImage cimg; cimg.CopyOf(img); CRect drawRect; drawRect.SetRect(rect.TopLeft().x, rect.TopLeft().y, rect.TopLeft().x + img->width - 1, rect.TopLeft().y + img->height - 1); cimg.DrawToHDC(hDc, &drawRect); ReleaseDC(pDC); //cv::imshow("view", img); //path1 //cvShowImage("view",img); //path2 // 著作权归作者所有。 // 商业转载请联系作者获得授权,非商业转载请注明出处。 // 作者:匿名用户 //链接:http://www.zhihu.com/question/29611790/answer/45053299 // 来源:知乎 //cv::Mat img2; //cv::Mat img1(img); // //CRect rect; //GetDlgItem(ID)->GetClientRect(&rect); //cv::Rect dst(rect.left,rect.top,rect.right,rect.bottom); //cv::resize(img1,img2,cv::Size(rect.Width(),rect.Height())); //imshow("view",img2); //unsigned int m_buffer[sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD)*256]; //BITMAPINFO* m_bmi = (BITMAPINFO*) m_buffer; //BITMAPINFOHEADER* m_bmih = &(m_bmi->bmiHeader); //memset(m_bmih, 0, sizeof(*m_bmih)); //m_bmih->biSize = sizeof(BITMAPINFOHEADER); //m_bmih->biWidth = img2.cols; //m_bmih->biHeight = -img2.rows; // 在自下而上的位图中 高度为负 //m_bmih->biPlanes = 1; //m_bmih->biCompression = BI_RGB; //m_bmih->biBitCount = 8 * img2.channels(); //CDC *pDC = GetDlgItem(ID)->GetDC(); //::StretchDIBits( // pDC->GetSafeHdc(), // 0, 0, rect.Width(), rect.Height(), // 0, 0, rect.Width(), rect.Height(), // img2.data, // (BITMAPINFO*) m_bmi, // DIB_RGB_COLORS, // SRCCOPY // ); //ReleaseDC(pDC); }
BOOL CDlgIBAFastlane::OnEraseBkgnd(CDC* pDC) { CRect rcRect; GetClientRect( rcRect ); CDC memDC; // Paint的内存DC CBitmap bmp; bmp.CreateCompatibleBitmap( pDC,rcRect.Width(),rcRect.Height() ); memDC.CreateCompatibleDC(NULL); memDC.SelectObject(&bmp); CBCGPToolBar* pParent = (CBCGPToolBar*)GetParent(); if( pParent ) { WINDOWPLACEMENT wp; this->GetWindowPlacement(&wp); CRect rcParent; pParent->GetClientRect(rcParent); // 绘制背景 CDC memParentDC; CBitmap bmpParent; bmpParent.CreateCompatibleBitmap(pDC,rcParent.Width(),rcParent.Height()); memParentDC.CreateCompatibleDC(NULL); memParentDC.SelectObject(&bmpParent); CDC* pParentDC = pParent->GetDC(); CBCGPVisualManager::GetInstance ()->OnFillBarBackground (&memParentDC, pParent, rcParent,rcParent); pParent->ReleaseDC(pParentDC); CRect rt = wp.rcNormalPosition; memDC.BitBlt(0,0,rcRect.Width(),rcRect.Height(),&memParentDC,wp.rcNormalPosition.left,wp.rcNormalPosition.top, SRCCOPY); pDC->BitBlt(0,0,rt.Width(),rt.Height(),&memDC,0,0,SRCCOPY); } CBitmap bmpImg; BOOL bRes = 0; if (m_bBugleActive) { bRes = bmpImg.LoadBitmap(IDB_BUGLE2); } else { bRes = bmpImg.LoadBitmap(IDB_BUGLE1); } if (bRes) { BITMAP bt; bmpImg.GetBitmap(&bt); CStatic *pStc = (CStatic*)GetDlgItem(IDC_PIC_BUGLE); CDC memDC; memDC.CreateCompatibleDC(pDC); memDC.SelectObject(&bmpImg); CRect rc; pStc->GetClientRect(rc); WINDOWPLACEMENT wp; pStc->GetWindowPlacement(&wp); CRect rcClient; GetClientRect(rcClient); rc.left = wp.rcNormalPosition.left; rc.top = rcClient.top + (rcClient.Height()-bt.bmHeight)/2; rc.right = rc.left + bt.bmWidth; rc.bottom = rc.top + bt.bmHeight; pDC->TransparentBlt(rc.left,rc.top,rc.Width(),rc.Height(),&memDC,0,0,rc.Width(),rc.Height(),RGB(255,255,255)); } else { IBA_ASSERT2(0,"喇叭image 问题"); } { WINDOWPLACEMENT pm; m_stcPicStatus.GetWindowPlacement(&pm); int nWidth = 85; int nHeight = 21; int nStatus = m_nIBAStatus; int nX = pm.rcNormalPosition.left; int nY = pm.rcNormalPosition.top; int nImgX = nStatus * nWidth; int nImgY = 0; BOOL bRes = m_imgStatus.Draw(pDC->GetSafeHdc(), nX, nY, nWidth, nHeight, nImgX, nImgY, nWidth, nHeight); pDC->SetBkMode(TRANSPARENT); CFont* pOldFont = (CFont*) pDC->SelectStockObject (DEFAULT_GUI_FONT); CStringArray strArr; CIBAHelpper::SplitLine(LOAD_STRING(IDS_IBA_NET_STATUS),strArr); CRect rcTest(0,0,0,0); CString strText = strArr.GetAt(nStatus); pDC->DrawText(strText,rcTest,DT_CALCRECT); CRect rcTxt; rcTxt.left = nX; rcTxt.right = nX + nWidth; rcTxt.top = nY + (nHeight - rcTest.Height())/2; rcTxt.bottom = rcTxt.top + rcTest.Height(); pDC->DrawText(strText,rcTxt,DT_CENTER); bRes = bRes; pDC->SelectObject(pOldFont); } //return CBCGPDialog::OnEraseBkgnd(pDC); return TRUE; }