DLLEXP bool save(WCHAR *fn) { CImage ci; ci.Create(g_snap_width,g_snap_height,32,0); BitBlt(ci.GetDC(),0,0,g_snap_width,g_snap_height,g_memdc.m_hDC,0,0,SRCCOPY); return SUCCEEDED(ci.Save(fn)); }
//旋转图片 VOID CImageEditorControl::SetRoundImage(BYTE cbRoundType) { //状态效验 ASSERT(m_ImageSource.IsNull()==false); if (m_ImageSource.IsNull()==true) return; //构造位置 CSize SizeSource(m_ImageSource.GetWidth(),m_ImageSource.GetHeight()); CSize SizeResult(m_ImageSource.GetHeight(),m_ImageSource.GetWidth()); //创建位图 CImage ImageSource; CImage ImageResult; ImageSource.Create(m_ImageSource.GetWidth(),m_ImageSource.GetHeight(),32); ImageResult.Create(m_ImageSource.GetHeight(),m_ImageSource.GetWidth(),32); //绘画位图 CDC * pDCResult=CDC::FromHandle(ImageResult.GetDC()); CDC * pDCSource=CDC::FromHandle(ImageSource.GetDC()); m_ImageSource.BitBlt(pDCSource->m_hDC,0,0,m_ImageSource.GetWidth(),m_ImageSource.GetHeight(),0,0); //获取属性 INT nPitchResult=ImageResult.GetPitch(); INT nPitchSource=ImageSource.GetPitch(); //获取数据 LPBYTE cbBitResult=(LPBYTE)ImageResult.GetBits(); LPBYTE cbBitSource=(LPBYTE)ImageSource.GetBits(); //创建区域 for (INT nYSourcePos=0;nYSourcePos<SizeSource.cy;nYSourcePos++) { for (INT nXSourcePos=0;nXSourcePos<SizeSource.cx;nXSourcePos++) { //目标位置 INT nXResultPos=(cbRoundType==ROUND_TYPE_LEFT)?nYSourcePos:(SizeSource.cy-nYSourcePos-1); INT nYResultPos=(cbRoundType==ROUND_TYPE_LEFT)?(SizeSource.cx-nXSourcePos-1):nXSourcePos; //设置颜色 DWORD dwSource=nYSourcePos*nPitchSource+nXSourcePos*4L; DWORD dwResult=nYResultPos*nPitchResult+nXResultPos*4L; *(COLORREF *)(cbBitResult+dwResult)=*(COLORREF *)(cbBitSource+dwSource); } } //释放对象 ImageSource.ReleaseDC(); ImageResult.ReleaseDC(); //更新图片 if (LoadEditImage(ImageResult)==false) { ASSERT(FALSE); return; } return; }
//绘画头像 void CExpression::DrawItem(CDC * pDC, int iXPos, int iYPos, bool bSelectec) { CExpressionItem * pExpressionItem=GetExpressItem(iYPos*m_wMaxRow+iXPos); int nFaceIndex = iYPos*m_wMaxRow+iXPos; if (pExpressionItem!=NULL) { if (bSelectec) { pDC->FillSolidRect(iXPos*(EP_PIC_WHIDE+PIC_SPACE)+PIC_SPACE/2,iYPos*(EP_PIC_HIGHT+PIC_SPACE)+PIC_SPACE/2, EP_PIC_WHIDE+PIC_SPACE,EP_PIC_HIGHT+PIC_SPACE,RGB(255,255,255)); pDC->Draw3dRect(iXPos*(EP_PIC_WHIDE+PIC_SPACE)+PIC_SPACE/2,iYPos*(EP_PIC_HIGHT+PIC_SPACE)+PIC_SPACE/2, EP_PIC_WHIDE+PIC_SPACE,EP_PIC_HIGHT+PIC_SPACE,RGB(28,57,208),RGB(28,57,208)); } else { pDC->FillSolidRect(iXPos*(EP_PIC_WHIDE+PIC_SPACE)+PIC_SPACE/2,iYPos*(EP_PIC_HIGHT+PIC_SPACE)+PIC_SPACE/2, EP_PIC_WHIDE+PIC_SPACE,EP_PIC_HIGHT+PIC_SPACE,RGB(255,255,255)); } //装载图片 TCHAR szFileName[MAX_PATH]=TEXT(""); _snprintf(szFileName,sizeof(szFileName),TEXT("%s\\Face\\%d.gif"),m_szPath, nFaceIndex); CImage ImageFace; if ( SUCCEEDED(ImageFace.Load(szFileName) ) ) { //背景判断 COLORREF rfColor = ImageFace.GetPixel(0,0); TransparentBlt(pDC->GetSafeHdc(), iXPos*(EP_PIC_WHIDE+PIC_SPACE)+PIC_SPACE,iYPos*(EP_PIC_HIGHT+PIC_SPACE)+PIC_SPACE, EP_PIC_WHIDE, EP_PIC_HIGHT, ImageFace.GetDC(), 0, 0, EP_PIC_WHIDE, EP_PIC_HIGHT, rfColor); ImageFace.ReleaseDC(); } } return; }
//输入解释 void CExpressionItem::InitExpressItem(LPCTSTR pszChineseName, LPCTSTR pszTrancelate, UINT uIDResource) { //设置变量 m_uImageID=uIDResource; lstrcpyn(m_szTrancelate,pszTrancelate,CountArray(m_szTrancelate)); lstrcpyn(m_szChineseName,pszChineseName,CountArray(m_szChineseName)); m_wTranceLength=lstrlen(m_szTrancelate); //加载图片 CSkinImage ImageFile; ImageFile.LoadFromResource(GetModuleHandle(CLIENT_SHARE_DLL_NAME),uIDResource); //创建表情 CImage ImageExpression; ASSERT(ImageFile.GetWidth()==EP_PIC_WHIDE); ASSERT(ImageFile.GetHeight()==EP_PIC_HIGHT); ImageExpression.Create(EP_PIC_WHIDE,EP_PIC_HIGHT,32); //绘画表情 CDC * pDC=CDC::FromHandle(ImageExpression.GetDC()); pDC->FillSolidRect(0,0,EP_PIC_WHIDE,EP_PIC_HIGHT,COLOR_CHAR_BK); ImageFile.AlphaDrawImage(pDC,0,0,RGB(255,0,255)); //设置图片 ImageExpression.ReleaseDC(); m_ImageDataObject.SetImage(ImageExpression.Detach()); return; };
// 画图片 void CImageViewDlg::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct) { if (nIDCtl == m_imageStatic.GetDlgCtrlID()) { CImage buffer; buffer.Create(lpDrawItemStruct->rcItem.right - lpDrawItemStruct->rcItem.left, lpDrawItemStruct->rcItem.bottom - lpDrawItemStruct->rcItem.top, 32); HDC dc = buffer.GetDC(); SetStretchBltMode(dc, HALFTONE); FillRect(dc, &lpDrawItemStruct->rcItem, (HBRUSH)GetStockObject(WHITE_BRUSH)); CRect rect; m_imageStatic.GetWindowRect(rect); int yOffset = -m_imageScrollBar.GetScrollPos(); for (const CImage& i : m_image) { if (i.IsNull()) continue; SIZE size = GetImageSize(i); if (yOffset >= rect.Height()) break; if (yOffset + size.cy > 0) i.Draw(dc, 0, yOffset, size.cx, size.cy); yOffset += size.cy; } FrameRect(dc, &lpDrawItemStruct->rcItem, (HBRUSH)GetStockObject(BLACK_BRUSH)); buffer.ReleaseDC(); buffer.Draw(lpDrawItemStruct->hDC, 0, 0); return; } CModelessDlg::OnDrawItem(nIDCtl, lpDrawItemStruct); }
void ListFileProvider::getThumbnail( ThumbnailManager& manager, int index, CImage& img, int w, int h, ThumbnailUpdater* updater ) { if ( index < 0 || getNumItems() <= index ) return; mutex_.grab(); std::string item; if ( isFiltering() ) item = searchResults_[ index ]->fileName; else item = items_[ index ]->fileName; mutex_.give(); // find thumbnail HICON extIcon = getExtensionIcons( item ); if ( extIcon ) { CBrush back; back.CreateSolidBrush( GetSysColor( COLOR_WINDOW ) ); img.Create( w, h, 32 ); CDC* pDC = CDC::FromHandle( img.GetDC() ); DrawIconEx( pDC->m_hDC, 0, 0, extIcon, w, h, 0, (HBRUSH)back, DI_NORMAL ); img.ReleaseDC(); } manager.create( item, img, w, h, updater ); }
void CChartCtrl::SaveAsImage(const TChartString& strFilename, const CRect& rect, int nBPP, REFGUID guidFileType) { //AFX_MANAGE_STATE(AfxGetStaticModuleState()); CImage chartImage; CRect chartRect = rect; if (chartRect.IsRectEmpty()) { GetClientRect(&chartRect); } chartImage.Create(chartRect.Width(), chartRect.Height(), nBPP); CDC newDC; newDC.Attach(chartImage.GetDC()); DrawBackground(&newDC, chartRect); chartRect.DeflateRect(3,3); DrawChart(&newDC, chartRect); newDC.Detach(); chartImage.Save(strFilename.c_str(), guidFileType); chartImage.ReleaseDC(); }
void CTreepadView::OnFileSaveAs() { if (!tree.size()) { return; } BOOL isOpen = FALSE; CString defaultDir = L"D:\\Treepad\\Iteration"; CString filter = L"PNG File (*.png)||"; CString fileName = L"image1.png"; //默认打开的文件名 CFileDialog openFileDlg(isOpen, L"png", fileName, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, filter, NULL); INT_PTR result = openFileDlg.DoModal(); CString filePath = defaultDir + "\\" + fileName; if (result == IDOK) { filePath = openFileDlg.GetPathName(); CRect rcBk; GetClientRect(&rcBk); CDC* pDC = GetDC(); CImage Image; Image.Create(rcBk.Width(), rcBk.Height(), 24); ::BitBlt(Image.GetDC(), 0, 0, rcBk.Width(), rcBk.Height(), pDC->m_hDC, 0, 0, SRCCOPY); Image.Save(filePath); Image.ReleaseDC(); Image.Destroy(); } // TODO: 在此添加命令处理程序代码 }
//绘画头像 VOID CFaceItemSelectWnd::DrawFaceItem(CDC * pDC, WORD wIndex, INT nXPos, INT nYPos, bool bHover) { //获取对象 ASSERT(CFaceItemControl::GetInstance()!=NULL); IFaceItemControl * pIFaceItemControl=CFaceItemControl::GetInstance(); //创建缓冲 CImage ImageBuffer; ImageBuffer.Create(FRAME_WIDTH+FACE_CX,FRAME_HEIGHT+FACE_CY,32); //绘画背景 CDC * pBufferDC=CDC::FromHandle(ImageBuffer.GetDC()); pBufferDC->FillSolidRect(0,0,FRAME_WIDTH+FACE_CX,FRAME_HEIGHT+FACE_CY,CR_BACK_FRAME); //绘画框架 BYTE cbFrameKind=(bHover==true)?ITEM_FRAME_HOVER:ITEM_FRAME_NORMAL; pIFaceItemControl->DrawFaceItemFrame(pBufferDC,FRAME_WIDTH/2,FRAME_HEIGHT/2,cbFrameKind); //绘画头像 pIFaceItemControl->DrawFaceNormal(pBufferDC,FRAME_WIDTH/2,FRAME_HEIGHT/2,wIndex); //绘画界面 pDC->BitBlt(nXPos,nYPos,FRAME_WIDTH+FACE_CX,FRAME_HEIGHT+FACE_CY,pBufferDC,0,0,SRCCOPY); //清理资源 ImageBuffer.ReleaseDC(); return; }
//处理图片 bool CRichEditMessage::LoadRichEditImage(HINSTANCE hInstance, UINT uResourceID, CDataObject&ImageDataObject) { //加载图片 CBitImage ImageFile; ImageFile.LoadFromResource(hInstance,uResourceID); //失败判断 if (ImageFile.IsNull()==true) { ASSERT(FALSE); return false; } //创建表情 CImage ImageRichEdit; ImageRichEdit.Create(ImageFile.GetWidth(),ImageFile.GetHeight(),32); //绘画表情 CDC * pDC=CDC::FromHandle(ImageRichEdit.GetDC()); pDC->FillSolidRect(0,0,ImageFile.GetWidth(),ImageFile.GetHeight(),m_crFillColor); ImageFile.TransDrawImage(pDC,0,0,RGB(255,0,255)); //设置图片 ImageRichEdit.ReleaseDC(); ImageDataObject.SetImage(ImageRichEdit.Detach()); return true; }
void HSliderCtrl::OnPaint() { CPaintDC dc(this); //获取位置 CRect rect; GetClientRect(&rect); //建双缓冲 CImage imgBuffer; CDC dcBuffer; imgBuffer.Create(rect.Width(), rect.Height(), 24); dcBuffer.Attach(imgBuffer.GetDC()); if (!m_imgBk.IsNull()) { m_imgBk.TransparentBlt(dcBuffer.GetSafeHdc(),0,0,rect.Width(),rect.Height(), 0,0,m_imgBk.GetWidth(),m_imgBk.GetHeight()/5,RGB(255,0,255)); CRect thuRect; GetThumbRect(&thuRect); m_imgBk.TransparentBlt(dcBuffer.GetSafeHdc(),thuRect.left,thuRect.top,thuRect.Width(),thuRect.Height(), 0,0+m_imgBk.GetHeight()/5*(m_byThuState+2),11,m_imgBk.GetHeight()/5,RGB(255,0,255)); m_imgBk.TransparentBlt(dcBuffer.GetSafeHdc(),0,0,thuRect.left,rect.Height(), 0,0+m_imgBk.GetHeight()/5,thuRect.left,m_imgBk.GetHeight()/5,RGB(255,0,255)); } //清除缓冲 dc.BitBlt(0, 0, rect.Width(), rect.Height(), &dcBuffer, 0, 0, SRCCOPY); dcBuffer.Detach(); imgBuffer.ReleaseDC(); }
void CBaseDialog::DrawClientArea( CDC*pDC,int nWidth,int nHeight ) { //创建缓冲 CImage ImageBuffer; ImageBuffer.Create(nWidth,nHeight,32); //变量定义 CDC * pBufferDC=CDC::FromHandle(ImageBuffer.GetDC()); pBufferDC->FillSolidRect(1,0,nWidth-2,nHeight,RGB(234,238,244)); if ( CHECK_IMAGE(m_pImageBack) ) { m_pImageBack->DrawImage(pBufferDC,0,0,nWidth-1,nHeight-1); } if ( CHECK_IMAGE(m_pShadow) ) { m_pShadow->DrawImage(pBufferDC,0,0,nWidth-1,nHeight-1); } DrawView(pBufferDC,nWidth-2,nHeight); pBufferDC->SetBkMode(TRANSPARENT); pBufferDC->SelectObject(RenderEngine->GetDeaultFont()); pBufferDC->SetTextColor(RGB(255,255,255)); //绘画界面 pDC->BitBlt(0,0,nWidth,nHeight,pBufferDC,0,0,SRCCOPY); //清理资源 ImageBuffer.ReleaseDC(); }
//绘制背景 BOOL CImageEditorControl::OnEraseBkgnd(CDC * pDC) { //获取大小 CRect rcClient; GetClientRect(&rcClient); //创建缓冲 CImage ImageBuffer; ImageBuffer.Create(rcClient.Width(),rcClient.Height(),32); //变量定义 HDC hBufferDC=ImageBuffer.GetDC(); CDC * pBufferDC=CDC::FromHandle(hBufferDC); //绘画背景 pBufferDC->FillSolidRect(&rcClient,RGB(255,255,255)); //绘画图像 if (m_ImageSource.IsNull()==false) { //加载图片 CPngImage ImageEditGray; ImageEditGray.LoadImage(GetModuleHandle(AVATAR_CONTROL_DLL_NAME),TEXT("FACE_EDIT_GRAY")); //设置环境 pBufferDC->SetStretchBltMode(HALFTONE); //绘画图片 m_ImageSource.StretchBlt(hBufferDC,(rcClient.Width()-m_SizeTarget.cx)/2,(rcClient.Height()-m_SizeTarget.cy)/2, m_SizeTarget.cx,m_SizeTarget.cy,0,0,m_SizeSource.cx,m_SizeSource.cy); //绘画蒙图 ImageEditGray.DrawImage(pBufferDC,(rcClient.Width()-m_SizeTarget.cx)/2,(rcClient.Height()-m_SizeTarget.cy)/2, m_SizeTarget.cx,m_SizeTarget.cy,0,0,ImageEditGray.GetWidth(),ImageEditGray.GetHeight()); //绘画图片 m_ImageSource.StretchBlt(hBufferDC,m_rcImageSelect.left,m_rcImageSelect.top,m_rcImageSelect.Width(),m_rcImageSelect.Height(), m_SizeSource.cx*(m_rcImageSelect.left-(rcClient.Width()-m_SizeTarget.cx)/2)/m_SizeTarget.cx, m_SizeSource.cy*(m_rcImageSelect.top-(rcClient.Height()-m_SizeTarget.cy)/2)/m_SizeTarget.cy, m_SizeSource.cx*m_rcImageSelect.Width()/m_SizeTarget.cx,m_SizeSource.cy*m_rcImageSelect.Height()/m_SizeTarget.cy); //绘画框架 DrawLineFrame(pBufferDC); } //绘画界面 pDC->BitBlt(0,0,rcClient.Width(),rcClient.Height(),pBufferDC,0,0,SRCCOPY); //清理资源 ImageBuffer.ReleaseDC(); return TRUE; }
//获取界面 bool CGameParrentView::GetGameViewImage(CImage & ImageBuffer, int nXPos, int nYPos, int nWidth, int nHeight) { ASSERT(ImageBuffer.IsNull()==false); ASSERT(m_ImageBuffer.IsNull()==false); if (m_ImageBuffer.IsNull()==false) { m_ImageBuffer.BitBlt(ImageBuffer.GetDC(),nXPos,nYPos,nWidth,nHeight,nXPos,nYPos); ImageBuffer.ReleaseDC(); return true; } return false; }
int savepng(TCHAR *szFilename) { HDC hdcSrc = GetDC(NULL); int nBitPerPixel = GetDeviceCaps(hdcSrc, BITSPIXEL); int nWidth = GetDeviceCaps(hdcSrc, HORZRES); int nHeight = GetDeviceCaps(hdcSrc, VERTRES); CImage image; image.Create(nWidth, nHeight, nBitPerPixel); BitBlt(image.GetDC(), 0, 0, nWidth, nHeight, hdcSrc, 0, 0, SRCCOPY); ReleaseDC(NULL, hdcSrc); image.ReleaseDC(); image.Save(szFilename, Gdiplus::ImageFormatPNG);//ImageFormatJPEG return 0; }
DLLEXP bool load(WCHAR *fn) { CImage ci; HRESULT hr=ci.Load(fn); if (!SUCCEEDED(hr)) { return false; } g_snap_height=ci.GetHeight(); g_snap_width=ci.GetWidth(); BitBlt(g_memdc.m_hDC,0,0,g_snap_width,g_snap_height,ci.GetDC(),0,0,SRCCOPY); g_bitmap.GetBitmapBits(g_scn_height*g_scn_width*4,g_buf_clr); return true; }
///<summary> /// OpenCVのimageデータであるMat型データをMFCのCImage型オブジェクトに変換してダイアログ表示(作成中) ///</summary> void CImageProcessor::ShowPictureDlg(cv::Mat cvImg) { cv::Size size = cvImg.size(); // 上下反転 cv::flip(cvImg, cvImg, 0); BITMAPINFO bmpInfo; bmpInfo.bmiHeader.biBitCount = cvImg.channels() * 8; bmpInfo.bmiHeader.biWidth = size.width; bmpInfo.bmiHeader.biHeight = size.height; bmpInfo.bmiHeader.biPlanes = 1; bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bmpInfo.bmiHeader.biCompression = BI_RGB; bmpInfo.bmiHeader.biClrImportant = bmpInfo.bmiHeader.biClrUsed = bmpInfo.bmiHeader.biSizeImage = bmpInfo.bmiHeader.biXPelsPerMeter = bmpInfo.bmiHeader.biYPelsPerMeter = 0; CImage* image = new CImage; image->Create(bmpInfo.bmiHeader.biWidth, bmpInfo.bmiHeader.biHeight, bmpInfo.bmiHeader.biBitCount); //HDC hdc = image->GetDC(); StretchDIBits( image->GetDC(), //HDC 0, 0, bmpInfo.bmiHeader.biWidth, bmpInfo.bmiHeader.biHeight,//コピー先サイズ 0, 0, bmpInfo.bmiHeader.biWidth, bmpInfo.bmiHeader.biHeight,//コピー元サイズ cvImg.data, &bmpInfo, DIB_RGB_COLORS, SRCCOPY); //http://chichimotsu.hateblo.jp/entry/20121130/1354265478 //HBITMAP hbmp = CreateCompatibleBitmap(hdc, bmpInfo.bmiHeader.biWidth, bmpInfo.bmiHeader.biHeight); //SetDIBits(hdc, hbmp, 0, bmpInfo.bmiHeader.biHeight, cvImg.data, &bmpInfo, DIB_RGB_COLORS); //HDC hdc2 = CreateCompatibleDC(hdc); //SelectObject(hdc2, hbmp); //BitBlt(hdc, 0, 0, bmpInfo.bmiHeader.biWidth, bmpInfo.bmiHeader.biHeight, hdc2, 0, 0, SRCCOPY); //DeleteDC(hdc2); //DeleteObject(hbmp); CPictureDlg dlg(image); dlg.DoModal(); if (image) { image->ReleaseDC(); delete image; image = NULL; } }
BOOL CUIDesignerView::SaveSkinImage(LPCTSTR pstrPathName) { CImage image; CWindowUI* pForm = m_LayoutManager.GetForm(); ASSERT(pForm); CSize szForm = pForm->GetInitSize(); CRect rcPaint(0,0,szForm.cx,szForm.cy); image.Create(szForm.cx, szForm.cy, 32); pForm->DoPaint(image.GetDC(), rcPaint); BOOL bRet = image.Save(pstrPathName, Gdiplus::ImageFormatJPEG); image.ReleaseDC(); return bRet; }
void Window::updateText() { CRect rectClient; GetClientRect(hWnd, &rectClient); CImage img; if(img.Create(rectClient.Width(), rectClient.Height(), 32, CImage::createAlphaChannel)) { drawText(img.GetDC()); img.ReleaseDC(); POINT pt = {0, 0}; SIZE size = {rectClient.Width(), rectClient.Height()}; BLENDFUNCTION bf = {0}; bf.BlendOp = AC_SRC_OVER; bf.BlendFlags = 0; bf.AlphaFormat = AC_SRC_ALPHA; bf.SourceConstantAlpha = 255; UpdateLayeredWindow(hWnd, 0, 0, &size, img.GetDC(), &pt, 0, &bf, ULW_ALPHA); img.ReleaseDC(); } }
//****************************************** HRESULT BMPanvas::LoadImage( CString name ) { HRESULT ret; CImage TI; if((ret=TI.Load(name))==S_OK) { HDC thdc=TI.GetDC(); hdc=CreateCompatibleDC(thdc); TI.ReleaseDC(); if(hdc!=NULL) { Attach(TI.Detach()); FileName=name; } } return ret; }
//重画函数 void CCardControl::OnPaint() { CPaintDC dc(this); //获取位置 CRect rcClient; GetClientRect(&rcClient); //加载位图 CImage ImageBuffer; CImageHandle HandleCard(&m_ImageCard); CImageHandle HandleFundus(&m_ImageBack); ImageBuffer.Create(rcClient.Width(),rcClient.Height(),16); if (ImageBuffer.IsNull()==true) return; //绘画扑克 CDC * pBufferDC=CDC::FromHandle(ImageBuffer.GetDC()); if(bDrawCard) //add { //add for (int i=0;i<m_CardDataArray.GetCount();i++) { BYTE bCardData=m_CardDataArray[i]; m_ImageCard.AlphaDrawImage(pBufferDC,i*CARD_SPACE,0,CARD_WIDTH,CARD_HEIGHT,GetCardXPos(bCardData),GetCardYPos(bCardData),RGB(255,0,255)); //非常好的画图函数 } } /////////////////////////////////////////////////////////////////////////////////////////begin add else { for(int i=0;i<m_CardDataArray.GetCount();i++) { m_ImageBack.AlphaDrawImage(pBufferDC,i*CARD_SPACE,0,CARD_WIDTH,CARD_HEIGHT,3*CARD_WIDTH,4*CARD_HEIGHT,RGB(255,0,255)); //画扑克背面 } } ///////////////////////////////////////////////////////////////////////////////////////////end add ImageBuffer.ReleaseDC(); ImageBuffer.BitBlt(dc,0,0); //清理资源 ImageBuffer.Destroy(); return; }
// クリップボードからビットマップを取得する関数 void SampleClipboard() { if(!::IsClipboardFormatAvailable(CF_BITMAP)) { return; } if(!::OpenClipboard(NULL)) { return; } CImage image; HBITMAP hBitmap = (HBITMAP)::GetClipboardData(CF_BITMAP); if(hBitmap == NULL) { ::CloseClipboard(); return; } CImage clip; // clip.Attach(hBitmap); // イメージを保持しているデバイス コンテキストを取得 HDC hdc = clip.GetDC(); setTextColor(hdc, RGB(255, 0, 0)); RECT rec; rec.top = 50; rec.left = 10; rec.right = 290; rec.bottom = 100; DrawText(hdc, "2019/04/12 XX:XX:XX", -1, &rec, NULL); clip.Detach(); clip.ReleaseDC(); ::CloseClipboard(); // そのままファイルに保存することも可能 // clip.Save(L"sample.png"); }
bool CDrawableWidget::GrabScreen(CImage & imgGrabTo) { GetClientRect(&m_rect); StretchBlt(imgGrabTo.GetDC(), 0, 0, imgGrabTo.GetWidth(), imgGrabTo.GetHeight(), SafeGrabDC()->GetSafeHdc(), 0, 0, m_rect.right, m_rect.bottom, SRCCOPY); imgGrabTo.ReleaseDC(); SafeReleaseDC(); return true; //GetClientRect(&m_rect); //HBITMAP hBmpResult = CreateCompatibleBitmap(GetDC()->GetSafeHdc(), // m_rect.right,m_rect.bottom); //return hBmpResult; }
//尺度变换 bool Scaling(CImage& srcImg,CImage& dstImg,double ratio) { int nHeight = srcImg.GetHeight(); int nWidth = srcImg.GetWidth(); if(dstImg.CreateEx((int)(nWidth*ratio),(int)(nHeight*ratio), 24, BI_RGB)) { HDC ImgDC = dstImg.GetDC(); int nPreMode = ::SetStretchBltMode(ImgDC, HALFTONE); srcImg.Draw(ImgDC, 0, 0, (int)(nWidth*ratio),(int)(nHeight*ratio), 0, 0, nWidth, nHeight); ::SetBrushOrgEx(ImgDC, 0, 0, NULL); ::SetStretchBltMode(ImgDC, nPreMode); dstImg.ReleaseDC(); } else { return false; } return true; }
bool scaleImage(CImage& srcImg,CImage& dstImg,int dstWidth,int dstHeight) { int nHeight = srcImg.GetHeight(); int nWidth = srcImg.GetWidth(); if(dstImg.CreateEx(dstWidth,dstHeight, 24, BI_RGB)) { HDC ImgDC = dstImg.GetDC(); int nPreMode = ::SetStretchBltMode(ImgDC, HALFTONE); srcImg.Draw(ImgDC, 0, 0, dstWidth,dstHeight, 0, 0, nWidth, nHeight); ::SetBrushOrgEx(ImgDC, 0, 0, NULL); ::SetStretchBltMode(ImgDC, nPreMode); dstImg.ReleaseDC(); } else { return false; } return true; }
///<summary> /// LPCOLORREFの画像データ配列をMFCのCImage型オブジェクトに変換してダイアログ表示 ///</summary> void CImageProcessor::ShowPictureDlg(LPCOLORREF pixelData, BITMAPINFO* bmpInfo) { CImage* image = new CImage; image->Create(bmpInfo->bmiHeader.biWidth, bmpInfo->bmiHeader.biHeight, bmpInfo->bmiHeader.biBitCount); StretchDIBits( image->GetDC(), //HDC 0, 0, bmpInfo->bmiHeader.biWidth, bmpInfo->bmiHeader.biHeight, //コピー先サイズ 0, 0, bmpInfo->bmiHeader.biWidth, bmpInfo->bmiHeader.biHeight, //コピー元サイズ pixelData, bmpInfo, DIB_RGB_COLORS, SRCCOPY); CPictureDlg dlg(image); dlg.DoModal(); if (image) { image->ReleaseDC(); delete image; image = NULL; } }
/*! @brief イメージの取得 @param [in] pSelectItem 選択データ @param [out] bitmap イメージ */ BOOL CImageFontDlg::GetBitmapImage(LPVOID pSelectItem, CImage &bitmap) { CRect rect; GetClientRect(&rect); bitmap.Create(rect.Width(), rect.Height(), 32); HDC hDC = bitmap.GetDC(); Gdiplus::Graphics graphics(hDC); graphics.Clear((Gdiplus::ARGB)Gdiplus::Color::White); CString strMessage; strMessage = _T("1234567890\n"); strMessage += _T("abcdefghijklmnopqrstuvwxyz\n"); strMessage += _T("ABCDEFGHIJKLMNOPQRSTUVWXYZ\n"); strMessage += _T("あいおえおかきくけこさしすせそたちつてとなにぬねの\n"); strMessage += _T("はひふへほまみむめもやゆよらりるれろわをん\n"); LOGFONT *pLogfont = (LOGFONT *) pSelectItem; Gdiplus::Font font(hDC, pLogfont); Gdiplus::RectF drawLayout(0, 0, (Gdiplus::REAL)rect.Width(), (Gdiplus::REAL)rect.Height()); Gdiplus::StringFormat stringFormat; stringFormat.SetAlignment(Gdiplus::StringAlignmentCenter); stringFormat.SetLineAlignment(Gdiplus::StringAlignmentCenter); stringFormat.SetTrimming(Gdiplus::StringTrimmingNone); Gdiplus::SolidBrush brush((Gdiplus::ARGB)Gdiplus::Color::Black); graphics.SetTextRenderingHint((Gdiplus::TextRenderingHint) (GetSpaceKeyDownCount() % (int)Gdiplus::TextRenderingHintClearTypeGridFit)); graphics.DrawString(strMessage, -1, &font, drawLayout, &stringFormat,&brush); bitmap.ReleaseDC(); return TRUE; }
//重画消息 VOID CWebPublicize::OnPaint() { CPaintDC dc(this); //获取位置 CRect rcClient; GetClientRect(&rcClient); //创建缓冲 CImage ImageBuffer; ImageBuffer.Create(rcClient.Width(),rcClient.Height(),32); //绘画缓冲 CDC * pBufferDC=CDC::FromHandle(ImageBuffer.GetDC()); DrawPublicizeView(pBufferDC,rcClient.Width(),rcClient.Height(),m_cbStatus); //绘画界面 dc.BitBlt(0,0,rcClient.Width(),rcClient.Height(),pBufferDC,0,0,SRCCOPY); //释放资源 ImageBuffer.ReleaseDC(); return; }
void CP1::main_do() { CClientDC dc(this); //下面是图片路径 zstringEx imgpath,zs; imgpath.getCtlText(IDC_EDIT2,this->m_hWnd); imgpath.trim(); if(imgpath.getStringLen()>0) { if(imgpath[imgpath.getStringLen()-1]!='\\')imgpath+='\\'; } //上面是取得图片路径 //////////////////////////////////////////////按序选文件 zs=imgpath.v(); zs+= face_img_dir[cur_order].name;cur_order++; //zs.setCtlText(IDC_EDIT4); zs.replaceB(0,".jpg",".bmp"); //如果是JPG文件,暂换为BMP zs.replaceB(0,".JPG",".bmp"); //从按序从枚举数组中取出文件名 ////////////////////////////////////////////按序选文件 //下面是把JPG转为BMP if( !zstringEx::is_file_exist(zs.v()) ) { zs.replaceB(0,".bmp",".jpg"); if(!zstringEx::is_file_exist(zs.v()))return; DRAWPIC.Destroy(); DRAWPIC.Load(zs.v()); zstringEx zs2;zs2.tools_GetCurDir(); zs2+="\\jpg2bmp.bmp"; //统一转化为BMP来进行 DRAWPIC.Save(zs2.v()); zs=zs2.v(); } DRAWPIC.Destroy(); DRAWPIC.Load(zs.v()); //if(DRAWPIC.GetWidth()>601)goto loopfor_only_320_small_pic; //大小限制,临时用的 //下面是把BMP进行缩小,过大的 if(DRAWPIC.GetWidth()>MY_IMAGE_MAX_WIDTH) { SMALLPIC.Create(MY_IMAGE_MAX_WIDTH, DRAWPIC.GetHeight()/((float)DRAWPIC.GetWidth()/MY_IMAGE_MAX_WIDTH), 24); HDC hdc=SMALLPIC.GetDC(); ::SetStretchBltMode(hdc,COLORONCOLOR); DRAWPIC.Draw(hdc,0,0,SMALLPIC.GetWidth(),SMALLPIC.GetHeight(),0,0,DRAWPIC.GetWidth(),DRAWPIC.GetHeight()); zstringEx zs2;zs2.tools_GetCurDir(); zs2+="\\cur_small.bmp"; //统一转化为BMP来进行 SMALLPIC.Save(zs2.v()); zs=zs2.v(); SMALLPIC.ReleaseDC(); SMALLPIC.Destroy(); DRAWPIC.Destroy(); DRAWPIC.Load(zs.v());//重装入 } //下面是把BMP进行缩小,过大的 if(DRAWPIC.GetHeight()>MY_IMAGE_MAX_HEIGHT) { SMALLPIC.Create(DRAWPIC.GetWidth()/((float)DRAWPIC.GetHeight()/MY_IMAGE_MAX_HEIGHT), MY_IMAGE_MAX_HEIGHT, 24); HDC hdc=SMALLPIC.GetDC(); ::SetStretchBltMode(hdc,COLORONCOLOR); DRAWPIC.Draw(hdc,0,0,SMALLPIC.GetWidth(),SMALLPIC.GetHeight(),0,0,DRAWPIC.GetWidth(),DRAWPIC.GetHeight()); zstringEx zs2;zs2.tools_GetCurDir(); zs2+="\\cur_small2.bmp"; //统一转化为BMP来进行 SMALLPIC.Save(zs2.v()); zs=zs2.v(); SMALLPIC.ReleaseDC(); SMALLPIC.Destroy(); DRAWPIC.Destroy(); DRAWPIC.Load(zs.v());//重装入 } this->RedrawWindow();//去掉原来的 DRAWPIC.Draw(dc,0,0);//在窗口上画图 //1.人脸检测 long zret= zFaceLocate( OID, //第一个函数返回的人脸识别实例对象ID zs.v(), //图像文件名,JPG,BMP cur_max_out_nums, //用户要求的最大人脸输出数 cur_sel_threshold, //人脸置信度阀值,高于这个阀值才会被输出 ofs); //2.报错信息 if(zret<0) { char er[256]; zGetLastError(OID,er); AfxMessageBox(er); } //CClientDC dc(this); POINT of;of.x=0;of.y=0; CString sbwh; for(int k=0;k<zret;k++) { //3.标记出选中的人脸 zFlagFace(OID,(LONG)this->m_hWnd,k,0,0); sbwh.Format("E1_W: %d E1_H: %d E2_W: %d E2_H: %d",ofs[k].eye1_w,ofs[k].eye1_h,ofs[k].eye2_w,ofs[k].eye2_h); GetDlgItem(6677)->SetWindowText(sbwh); //dc.Rectangle(ofs[k].eye1_x-ofs[k].eye1_w/2, // ofs[k].eye1_y-ofs[k].eye1_h/2, // ofs[k].eye1_x+ofs[k].eye1_w/2, // ofs[k].eye1_y+ofs[k].eye1_h/2) ; //dc.Rectangle(ofs[k].eye2_x-ofs[k].eye2_w/2, // ofs[k].eye2_y-ofs[k].eye2_h/2, // ofs[k].eye2_x+ofs[k].eye2_w/2, // ofs[k].eye2_y+ofs[k].eye2_h/2) ; //4.在其下打分 CString outdf; outdf.Format("%d: %0.2f",k+1,ofs[k].tally); dc.TextOut(ofs[k].left,ofs[k].bottom,outdf); } //5.回收人脸检测内存 zFaceLocate_FreeMemory(OID); }//end func
//重画消息 VOID CDlgSkinControl::OnPaint() { CPaintDC dc(this); //获取位置 CRect rcClient; GetClientRect(&rcClient); //创建缓冲 CImage ImageBuffer; ImageBuffer.Create(rcClient.Width(),rcClient.Height(),32); //变量定义 CDC * pDC=CDC::FromHandle(ImageBuffer.GetDC()); CSkinRenderManager * pSkinRenderManager=CSkinRenderManager::GetInstance(); //绘画背景 pDC->FillSolidRect(&rcClient,CSkinDialog::m_SkinAttribute.m_crBackGround); pDC->Draw3dRect(&rcClient,CSkinEdit::m_SkinAttribute.m_crEnableBorad,CSkinEdit::m_SkinAttribute.m_crEnableBorad); //加载资源 CPngImageSB ImageSkinItem; ImageSkinItem.LoadImage(AfxGetInstanceHandle(),TEXT("SKIN_ITEM")); //绘画子项 for (WORD nXPos=0;nXPos<4;nXPos++) { for (WORD nYPos=0;nYPos<2;nYPos++) { //变量定义 WORD wIndex=nYPos*4+nXPos; WORD wImageIndex=(m_wHoverItem==wIndex)?1:0; tagSkinRenderInfo & SkinRenderInfo=m_RenderInfoItem[wIndex]; //绘画子项 ImageSkinItem.DrawImage(pDC,nXPos*(m_SizeSkinItem.cx+ITEM_SPACE_CX)+ITEM_ORIGIN_X, nYPos*(m_SizeSkinItem.cy+ITEM_SPACE_CY)+ITEM_ORIGIN_Y,m_SizeSkinItem.cx,m_SizeSkinItem.cy, (nYPos*4+nXPos)*m_SizeSkinItem.cx,wImageIndex*m_SizeSkinItem.cy); //绘画边框 if ((m_CurrentRenderInfo.wColorH==SkinRenderInfo.wColorH)&&(m_CurrentRenderInfo.dRectifyS==SkinRenderInfo.dRectifyS) &&(m_CurrentRenderInfo.dRectifyB==SkinRenderInfo.dRectifyB)) { INT nXDrawPos=nXPos*(m_SizeSkinItem.cx+ITEM_SPACE_CX)+ITEM_ORIGIN_X-2; INT nYDrawPos=nYPos*(m_SizeSkinItem.cy+ITEM_SPACE_CY)+ITEM_ORIGIN_Y-2; pDC->Draw3dRect(nXDrawPos,nYDrawPos,m_SizeSkinItem.cx+4,m_SizeSkinItem.cy+4,RGB(0,0,0),RGB(0,0,0)); } } } //加载资源 CPngImageSB ImageSkinColor; CPngImageSB ImageSkinButton; ImageSkinColor.LoadImage(AfxGetInstanceHandle(),TEXT("SKIN_COLOR")); ImageSkinButton.LoadImage(AfxGetInstanceHandle(),TEXT("SKIN_BUTTON")); //绘画色条 for (WORD nIndex=0;nIndex<3;nIndex++) { //绘画色条 INT nXDrawPos=COLOR_ORIGIN_X; INT nYDrawPos=COLOR_ORIGIN_Y+(m_SizeColorItem.cy+COLOR_SPACE_CY)*nIndex; ImageSkinColor.DrawImage(pDC,nXDrawPos,nYDrawPos,m_SizeColorItem.cx,m_SizeColorItem.cy,0,m_SizeColorItem.cy*nIndex); //绘画滑块 switch (nIndex) { case 0: //色相 { INT nXButtonPos=nXDrawPos+(m_SizeColorItem.cx-6)*m_CurrentRenderInfo.wColorH/(MAX_COLOR_H-MIN_COLOR_H)+3; ImageSkinButton.DrawImage(pDC,nXButtonPos-ImageSkinButton.GetWidth()/2,nYDrawPos-5); break; } case 1: //饱和 { DOUBLE dRectifyS=(m_CurrentRenderInfo.dRectifyS*100-MIN_COLOR_S)/(MAX_COLOR_S-MIN_COLOR_S); INT nXButtonPos=(INT)(nXDrawPos+(DOUBLE)(m_SizeColorItem.cx-6)*dRectifyS+3); ImageSkinButton.DrawImage(pDC,nXButtonPos-ImageSkinButton.GetWidth()/2,nYDrawPos-5); break; } case 2: //亮度 { DOUBLE dRectifyB=(m_CurrentRenderInfo.dRectifyB*100-MIN_COLOR_B)/(MAX_COLOR_B-MIN_COLOR_B); INT nXButtonPos=(INT)(nXDrawPos+(DOUBLE)(m_SizeColorItem.cx-6)*dRectifyB+3); ImageSkinButton.DrawImage(pDC,nXButtonPos-ImageSkinButton.GetWidth()/2,nYDrawPos-5); break; } } } //设置环境 pDC->SetBkMode(TRANSPARENT); pDC->SetTextColor(RGB(0,0,0)); pDC->SelectObject(CSkinResourceManager::GetInstance()->GetDefaultFont()); //绘画字符 LPCTSTR pszCustom=TEXT("自我定制:"); LPCTSTR pszRecommend=TEXT("推荐配色:"); pDC->TextOut(10,102,pszCustom,lstrlen(pszCustom)); pDC->TextOut(10,14,pszRecommend,lstrlen(pszRecommend)); //绘画界面 dc.BitBlt(0,0,rcClient.Width(),rcClient.Height(),pDC,0,0,SRCCOPY); //清理资源 ImageBuffer.ReleaseDC(); return; }