void CollisionTypePanel::OnPaint(wxPaintEvent& event) { //Double buffered dest dc wxAutoBufferedPaintDC destDC(this); //Get renderable client rect wxSize clientSize = GetClientSize(); wxRect clientRect(0, 0, clientSize.x, clientSize.y); //Clear dest rect destDC.SetBrush(*wxBLACK_BRUSH); destDC.DrawRectangle(clientRect); //No outline destDC.SetPen(wxNullPen); const int maxCollisionTypesPerLayer = 16; //TODO: Multiple layers const int numCollisionLayers = 1; float rectSize = (m_orientation == eVertical) ? (clientSize.y / maxCollisionTypesPerLayer) : (clientSize.x / maxCollisionTypesPerLayer); wxBitmap bitmap(sIconWidth, sIconHeight, wxBITMAP_SCREEN_DEPTH); wxMemoryDC bitmapDC(bitmap); for(int i = 0; i < numCollisionLayers; i++) { for(int j = 0; j < maxCollisionTypesPerLayer; j++) { int x = (m_orientation == eVertical) ? i : j; int y = (m_orientation == eVertical) ? j : i; wxBrush brush; CollisionType* collisionType = m_project->GetCollisionType(1 << j); if(collisionType) { bitmapDC.DrawBitmap(m_icons[(i * maxCollisionTypesPerLayer) + j], 0, 0); destDC.StretchBlit(x * rectSize, y * rectSize, rectSize, rectSize, &bitmapDC, 0, 0, sIconWidth, sIconHeight); } else { brush.SetStyle(wxBRUSHSTYLE_CROSSDIAG_HATCH); brush.SetColour(wxColour(100, 100, 100, 50)); destDC.SetBrush(brush); destDC.DrawRectangle(x * rectSize, y * rectSize, rectSize, rectSize); } } } }
void CHTMLViewCapView::SaveImages(CList<CHTMLViewCapUrl> &lstUrl) { // POSITION pos = NULL; // 浏览器和图片的宽度和高度 DWORD nWidth = 1024; DWORD nHeight = 2048; IDispatch *pDoc = NULL; IViewObject *pViewObject = NULL; VARIANT vUrl; VARIANT vUrlName; // CTime t; CString csTime, csDate, csMark1; CString csPath; CString csFileName; HRESULT hr; // CBitmap *pBM; Bitmap *gdiBMP; // 用于生成图片的序数 static DWORD nNum = 0; /* 创建字体 */ HFONT hfont; LOGFONT lf; ZeroMemory(&lf, sizeof(lf)); lf.lfHeight = 0; lf.lfWidth = 0; lf.lfEscapement = 0; lf.lfOrientation = 0; lf.lfStrikeOut = FALSE; lf.lfCharSet = DEFAULT_CHARSET; lf.lfOutPrecision = OUT_DEFAULT_PRECIS; lf.lfClipPrecision = CLIP_DEFAULT_PRECIS; lf.lfQuality = ANTIALIASED_QUALITY; lf.lfPitchAndFamily = VARIABLE_PITCH; lstrcpy(lf.lfFaceName, _T("微软雅黑")); hfont = CreateFontIndirect(&lf); // 循环遍历所有URL for (pos = lstUrl.GetHeadPosition(); pos != NULL; lstUrl.GetNext(pos)) { // 获取图片和浏览器分辨率 nWidth = lstUrl.GetAt(pos).m_nWidth; nHeight = lstUrl.GetAt(pos).m_nHeight; CString &csUrl = lstUrl.GetAt(pos).m_csUrl; CBitmapDC destDC(nWidth, nHeight); // 创建 媒体名称目录 csPath = ::theApp.m_csImageDir; csPath.Append(_T("\\")); if (lstUrl.GetAt(pos).m_bHasMediaName) { csPath.Append(lstUrl.GetAt(pos).m_csMediaName); } else { csPath.Append(lstUrl.GetAt(pos).getMediaNameInUrl()); } ::CreateDirectory(csPath, NULL); // 创建输出文件路径 t = CTime::GetCurrentTime(); csTime = t.Format("\\%H时%M分%S秒-"); csMark1 = t.Format("%H:%M"); csDate = t.Format(" %Y/%m/%d"); csPath.Append(csTime); vUrl.vt = ::VT_BSTR; vUrl.bstrVal = (BSTR)csUrl.GetString(); m_pBrowserApp->put_Width(nWidth); m_pBrowserApp->put_Height(nHeight); if (m_pBrowserApp->Navigate2(&vUrl, NULL, NULL, NULL, NULL) == S_OK) { m_tBeforeEnterLoop = CTime::GetCurrentTime(); RunModalLoop(); } else { TRACE(_T("%d Document Navigate Failed!\n"), vUrl); MessageBox(_T("Navi Error"), _T("Error"), MB_OK); return ; } TRACE("Begin Cap!\n"); // wait for document to load m_pBrowserApp->Refresh(); // render to enhanced metafile HDC. hr = m_pBrowserApp->get_Document(&pDoc); if (hr != S_OK) { TRACE(_T("%s get_Document failed!\n"), vUrl.bstrVal); return ; } pDoc->QueryInterface(IID_IViewObject, (void**)&pViewObject); // result is first div of document if (pDoc == NULL) { TRACE(_T("%d query IID_IViewObject failed!\n"), vUrl.bstrVal); return ; } hr = OleDraw(pViewObject, DVASPECT_CONTENT, destDC, NULL); if (hr != S_OK) { TRACE(_T("%s OleDraw failed!\n"), vUrl.bstrVal); return ; } /* 使用字体 */ destDC.SelectObject(hfont); destDC.SetTextColor(RGB(0, 0, 0)); destDC.SetBkColor(RGB(235, 231, 228)); //destDC.SetBkMode(TRANSPARENT); // 输出水印 TextOut(destDC, nWidth - 70, nHeight - 100, (LPCTSTR)csMark1, csMark1.GetLength()); TextOut(destDC, nWidth - 100, nHeight - 70, (LPCTSTR)csDate, csDate.GetLength()); pBM = destDC.Close(); gdiBMP = Bitmap::FromHBITMAP(HBITMAP(pBM->GetSafeHandle()), NULL); csFileName.Format(_T("%u.jpg"), nNum++); csPath.Append(csFileName); // 保存图片 gdiBMP->Save(csPath.GetString(), &m_jpegClsid, NULL); // 清理资源 delete gdiBMP; pBM->DeleteObject(); pViewObject->Release(); pDoc->Release(); } }