BOOL CChildView::OnEraseBkgnd(CDC* pDC) { CRect r; CAutoLock cAutoLock(&m_csLogo); CImage img; img.Attach(m_logo); if (((CMainFrame*)GetParentFrame())->IsSomethingLoaded()) { pDC->ExcludeClipRect(m_vrect); } else if (!img.IsNull()) { GetClientRect(r); int w = min(img.GetWidth(), r.Width()); int h = min(img.GetHeight(), r.Height()); int x = (r.Width() - w) / 2; int y = (r.Height() - h) / 2; r = CRect(CPoint(x, y), CSize(w, h)); int oldmode = pDC->SetStretchBltMode(STRETCH_HALFTONE); img.StretchBlt(*pDC, r, CRect(0, 0, img.GetWidth(), img.GetHeight())); pDC->SetStretchBltMode(oldmode); pDC->ExcludeClipRect(r); } img.Detach(); GetClientRect(r); pDC->FillSolidRect(r, 0); return TRUE; }
void CDrawCtrl::SaveImage() { CDC* dc; dc = GetDC(); CString sFileName; sFileName.Format(L"\\temp\\Draw_%s.bmp", CUtil::GetCurrentTimeStamp()); CDC memDC; memDC.CreateCompatibleDC(dc); BYTE *lpBitmapBits = NULL; CBitmap bm; CRect r; GetClientRect(r); BITMAPINFO bi; ZeroMemory(&bi, sizeof(BITMAPINFO)); bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bi.bmiHeader.biWidth = r.Width(); bi.bmiHeader.biHeight = r.Height(); bi.bmiHeader.biPlanes = 1; bi.bmiHeader.biBitCount = 24; HBITMAP bitmap = CreateDIBSection(memDC.GetSafeHdc(), &bi, DIB_RGB_COLORS, (LPVOID*)&lpBitmapBits, NULL, 0); HGDIOBJ oldbmp = SelectObject(memDC.GetSafeHdc(), bitmap); BitBlt(memDC.GetSafeHdc(), 0, 0, r.Width(), r.Height(), dc->GetSafeHdc(), 0, 0, SRCCOPY); BITMAPFILEHEADER bh; ZeroMemory(&bh, sizeof(BITMAPFILEHEADER)); bh.bfType = 0x4d42; //bitmap bh.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER); bh.bfSize = bh.bfOffBits + ((r.Width()*r.Height())*3); CFile file; if(file.Open(sFileName, CFile::modeCreate | CFile::modeWrite)) { file.Write(&bh, sizeof(BITMAPFILEHEADER)); file.Write(&(bi.bmiHeader), sizeof(BITMAPINFOHEADER)); file.Write(lpBitmapBits, 3 * r.Width() * r.Height()); file.Close(); } SelectObject(memDC.GetSafeHdc(), oldbmp); DeleteObject(bitmap); memDC.DeleteDC(); dc->DeleteDC(); #ifndef _WIN32_WCE CImage img; img.Attach((HBITMAP)bm.m_hObject); img.Save(L"c:\\temp\\teste.jpg", Gdiplus::ImageFormatJPEG); #endif }
BOOL CChildView::OnEraseBkgnd(CDC* pDC) { CRect r; CImage img; img.Attach(m_img); if ((m_pMainFrame->GetLoadState() != MLS::CLOSED || (!m_bFirstMedia && m_pMainFrame->m_controls.DelayShowNotLoaded())) && !m_pMainFrame->IsD3DFullScreenMode() && !m_pMainFrame->m_fAudioOnly) { pDC->ExcludeClipRect(m_vrect); } else if (!img.IsNull()) { const double dImageAR = double(img.GetWidth()) / img.GetHeight(); GetClientRect(r); int width = r.Width(); int height = r.Height(); if (!m_bCustomImgLoaded) { // Limit logo size // TODO: Use vector logo to preserve quality and remove limit. width = std::min(img.GetWidth(), width); height = std::min(img.GetHeight(), height); } double dImgWidth = height * dImageAR; double dImgHeight; if (width < dImgWidth) { dImgWidth = width; dImgHeight = dImgWidth / dImageAR; } else { dImgHeight = height; } int x = std::lround((r.Width() - dImgWidth) / 2.0); int y = std::lround((r.Height() - dImgHeight) / 2.0); r = CRect(CPoint(x, y), CSize(std::lround(dImgWidth), std::lround(dImgHeight))); if (!r.IsRectEmpty()) { if (m_resizedImg.IsNull() || r.Width() != m_resizedImg.GetWidth() || r.Height() != m_resizedImg.GetHeight() || img.GetBPP() != m_resizedImg.GetBPP()) { m_resizedImg.Destroy(); m_resizedImg.Create(r.Width(), r.Height(), std::max(img.GetBPP(), 24)); HDC hDC = m_resizedImg.GetDC(); SetStretchBltMode(hDC, STRETCH_HALFTONE); img.StretchBlt(hDC, 0, 0, r.Width(), r.Height(), SRCCOPY); m_resizedImg.ReleaseDC(); } m_resizedImg.BitBlt(*pDC, r.TopLeft()); pDC->ExcludeClipRect(r); } } img.Detach(); GetClientRect(r); pDC->FillSolidRect(r, 0); return TRUE; }
void Utils::SaveBitmapToFile(CBitmap * bmp) { CImage image; CString Path; Path.Format("C:\\test%d.bmp", counter); image.Attach(*bmp); image.Save(Path, Gdiplus::ImageFormatBMP); image.Detach(); counter++; }
HRESULT BMPanvas::SaveImage(CString name) { HRESULT ret = E_FAIL; CImage TI; if(HasImage()) { TI.Attach(GetHBMP(BMP_DETACH)); ret=TI.Save(name,ImageFormatPNG); Attach(TI.Detach()); } return ret; }
LRESULT CChildView::OnHPTimer(WPARAM wParam, LPARAM) { // Get the screen region to copy. // CRect rect(MeaToolMgr::Instance().GetRegion()); // Create a memory context and bitmap for it. // HDC screenDC = ::CreateDC(_T("DISPLAY"), NULL, NULL, NULL); HDC memDC = ::CreateCompatibleDC(screenDC); HBITMAP screenBitmap = ::CreateCompatibleBitmap(screenDC, rect.Width(), rect.Height()); ::SelectObject(memDC, screenBitmap); // Copy the screen region to the bitmap. // ::BitBlt(memDC, 0, 0, rect.Width(), rect.Height(), screenDC, rect.left, rect.top, SRCCOPY); if((MeaTimer *)wParam == &m_screenGrabTimer) { // Save bitmap to file // CImage img; CTime currentTime = CTime::GetCurrentTime(); CString newFilename = currentTime.Format(_T("Grab %Y-%m-%d %H.%M.%S")); CString filePath = (m_screenGrabDirectory == _T("") ? m_screenGrabDirectory : m_screenGrabDirectory + _T("\\")); CString filename(filePath + newFilename + _T(".png")); img.Attach(screenBitmap); img.Save(filename); img.Detach(); } else { // Put bitmap on the clipboard. // ::EmptyClipboard(); ::SetClipboardData(CF_BITMAP, screenBitmap); ::CloseClipboard(); } // Cleanup // ::DeleteDC(screenDC); MeaToolMgr::Instance().EnableRadioTool(); return 0; }
void Cmp3taggerDlg::CleanCover() { CBitmap nocover; nocover.LoadBitmap(IDB_NOCOVER); CImage img; img.Attach(nocover); CDC *pdc = m_stCover.GetDC(); HDC hdc = pdc->GetSafeHdc(); SetStretchBltMode(hdc, HALFTONE); img.StretchBlt(hdc, 0, 0, 150, 150); }
// クリップボードからビットマップを取得する関数 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"); }
void MFC_VIEWER::SavePicture(CString path){ CImage img; img.Attach((HBITMAP)bitmap); img.Save(path); }
void CDlgCapCam::UpdateImage(void) { int i; CPen cur_pen, *old_pen=NULL; CBrush cur_brush,*old_brush = NULL; CPoint point; CSize size; CRect rect_image; CImage * pimage; CString str_dis; CRect client_rect1; CSize paint_size1; __time32_t l_time; if (!m_img_show.IsNull()) { pimage = &m_img_show; _time32(&l_time); CWnd * pDis1 = GetDlgItem(IDC_STATIC_IMGSHOW); CDC* pDC1 = pDis1->GetDC(); CDC MemDC1; CBitmap MemBitmap1; CPen pen_target; rect_image = CRect(0,0,pimage->GetWidth()-1, pimage->GetHeight()-1); pDis1->GetClientRect(&client_rect1); MemDC1.CreateCompatibleDC(pDC1); MemBitmap1.CreateCompatibleBitmap(pDC1,rect_image.Width(),rect_image.Height()); MemDC1.SelectObject(&MemBitmap1); MemDC1.SetStretchBltMode(COLORONCOLOR); pDC1->SetStretchBltMode(COLORONCOLOR); pimage->BitBlt(MemDC1.GetSafeHdc(),rect_image, CPoint(0,0),SRCCOPY); //draw other osd targets pen_target.CreatePen(PS_SOLID, 2, RGB(255, 0, 0)); MemDC1.SelectStockObject(NULL_BRUSH); MemDC1.SelectObject(&pen_target); for (i=0; i<m_proc_result_buf.target_set.num; i++) { MemDC1.Rectangle(m_proc_result_buf.target_set.targets[i].rect.left, m_proc_result_buf.target_set.targets[i].rect.bottom, m_proc_result_buf.target_set.targets[i].rect.right, m_proc_result_buf.target_set.targets[i].rect.top); } //修改事件抓拍为每10秒钟1次 #define SNATCH_TIME_INTER 10 #define SNATCH_TIME_LATE 120 time_t cur_time; struct tm * now_time; time(&cur_time); now_time = localtime(&cur_time); if (m_proc_result_buf.target_set.num > 0) { if (cur_time - m_trigger_snatch_time >= SNATCH_TIME_INTER) { //超过10s间隔 ScreenShot(1, SNATCH_TIME_INTER); m_trigger_snatch_time = cur_time; } } //延续120秒 else if(m_trigger_snatch_time > 0 && cur_time - m_trigger_snatch_time <=SNATCH_TIME_LATE) { ScreenShot(SNATCH_TIME_LATE/SNATCH_TIME_INTER, SNATCH_TIME_INTER); m_trigger_snatch_time = 0; } if (!m_proc_result_buf.flg_used) { if (m_proc_result_buf.target_set.num) { ((CSTEvaluationDlg*)pWndParent)->AddTarget(&m_proc_result_buf.target_set); } //do event for (i=0; i<m_proc_result_buf.event_set.num; i++) { //摄像头采集的,帧数置零 ((CSTEvaluationDlg*)pWndParent)->AddEvent(0,l_time,m_proc_result_buf.event_set.events[i].type); //同时触发抓拍 //ScreenShot(12, 10); } //防止由于刷新,事件被触发两次 m_proc_result_buf.flg_used = TRUE; } //---------------------抓拍的操作------------------- //if (WaitForSingleObject(m_proc_flgscreenshot, 0) == WAIT_OBJECT_0) if (m_snatch_count>0 && l_time - m_snatch_pretime>=m_snatch_intertime) { CImage img; CString str_name; time_t cur_time; struct tm * now_time; str_name = ((CSTEvaluationDlg*)pWndParent)->file_path; str_name += +_T("\\screenshot\\"); time(&cur_time); now_time = localtime(&cur_time); str_name.AppendFormat(_T("_%012d_alarm.jpg"), cur_time); img.Attach(MemBitmap1); img.Save(str_name); img.Detach(); m_snatch_count--; m_snatch_pretime = l_time; } pDC1->StretchBlt(0,0,STE_IMAGE_WIDTH*2-1,STE_IMAGE_HEIGH*2-1,&MemDC1,0,0,rect_image.Width()-1, rect_image.Height()-1, SRCCOPY); pDis1->ReleaseDC(pDC1); } else { pimage = &m_img_def; CWnd * pDis1 = GetDlgItem(IDC_STATIC_IMGSHOW); CDC* pDC1 = pDis1->GetDC(); rect_image = CRect(0,0,pimage->GetWidth()-1, pimage->GetHeight()-1); pDis1->GetClientRect(&client_rect1); pimage->StretchBlt(pDC1->GetSafeHdc(),client_rect1, rect_image, SRCCOPY); pDis1->ReleaseDC(pDC1); } #ifdef _DEBUG if (!m_img1.IsNull()) { pimage = &m_img1; //CWnd * pDis1 = GetDlgItem(IDC_STATIC_IMGSHOW); CDC* pDC1 = GetDC(); rect_image = CRect(0,0,pimage->GetWidth()-1, pimage->GetHeight()-1); GetClientRect(&client_rect1); pimage->StretchBlt(pDC1->GetSafeHdc(),CRect(380,20, 380+175, 20+143), rect_image); //pimage->BitBlt(pDC1->GetSafeHdc(), 500,0,352,288, 0,0,SRCCOPY); ReleaseDC(pDC1); } if (!m_img2.IsNull()) { pimage = &m_img2; //CWnd * pDis1 = GetDlgItem(IDC_STATIC_IMGSHOW); CDC* pDC1 = GetDC(); rect_image = CRect(0,0,pimage->GetWidth()-1, pimage->GetHeight()-1); GetClientRect(&client_rect1); pimage->StretchBlt(pDC1->GetSafeHdc(),CRect(380,170, 380+175, 170+143), rect_image); //pimage->BitBlt(pDC1->GetSafeHdc(), 500,0,352,288, 0,0,SRCCOPY); ReleaseDC(pDC1); } if (!m_img3.IsNull()) { pimage = &m_img3; //CWnd * pDis1 = GetDlgItem(IDC_STATIC_IMGSHOW); CDC* pDC1 = GetDC(); rect_image = CRect(0,0,pimage->GetWidth()-1, pimage->GetHeight()-1); GetClientRect(&client_rect1); pimage->StretchBlt(pDC1->GetSafeHdc(),CRect(560,20, 560+175, 20+143), rect_image); //pimage->BitBlt(pDC1->GetSafeHdc(), 500,0,352,288, 0,0,SRCCOPY); ReleaseDC(pDC1); } if (!m_img4.IsNull()) { pimage = &m_img4; //CWnd * pDis1 = GetDlgItem(IDC_STATIC_IMGSHOW); CDC* pDC1 = GetDC(); rect_image = CRect(0,0,pimage->GetWidth()-1, pimage->GetHeight()-1); GetClientRect(&client_rect1); pimage->StretchBlt(pDC1->GetSafeHdc(),CRect(560,170, 560+175, 170+143), rect_image); //pimage->BitBlt(pDC1->GetSafeHdc(), 500,0,352,288, 0,0,SRCCOPY); ReleaseDC(pDC1); } #endif //因为帧数等信息和图像相关,所以也放在此处更新 __time32_t n_time = 0; if (m_flg_process) { _time32(&n_time); } //str_dis.Format(_T("Frame:%06d; Time(s):%06d"), m_proc_result_buf.frame_index, n_time-m_start_time); str_dis.Format(_T("Frame:%02d; Time: %02dm:%02ds"), m_proc_result_buf.frame_index, (n_time-m_start_time)/60, (n_time-m_start_time)%60); GetDlgItem(IDC_STATIC_STATUS)->SetWindowText(str_dis); }
bool EmbedeedFontMan::AddFont(const CString sFontFolder, const CString sFontName){ CString sDir = sFontFolder; if( sDir.GetAt(sDir.GetLength() - 1) != '\\' ) sDir += _T("\\"); EmbedeedFont* pFont = new EmbedeedFont(); // Load characters code map. {{ BYTE* lpContent = NULL; int nSize = 0; if( Path::ReadFileContent(sDir + _T("codes.txt"), lpContent, nSize) && nSize > 0 ){ CString sContent; memcpy(sContent.GetBufferSetLength(nSize), lpContent, nSize); CStringArray arrStrings; StringHelper::Split(&sContent, _T(";"), arrStrings); CString sCharCode; for(int i=0; i<arrStrings.GetCount(); i++){ sCharCode = arrStrings.GetAt(i); int nCharCode = 0; // Hex value if( sCharCode.GetAt(0) == '#' ) nCharCode = StringHelper::HexStringIntoInt(&((TCHAR*)sCharCode.GetBuffer())[1], sCharCode.GetLength() - 1); else nCharCode = _ttoi(sCharCode.GetBuffer()); pFont->m_arrCharacters.Add((void*)nCharCode, (void*)i); } } else{ #ifdef _DEBUG CString sMsg; sMsg.Format(_T("Couldn't find %s"), sDir + _T("codes.txt")); AfxMessageBox(sMsg); #endif if( lpContent ) delete [] lpContent; delete pFont; return false; } // }} if( lpContent ){ delete [] lpContent; lpContent = NULL; } CStringArray arrFileNames; if( Path::GetFilesByExtention(sDir, _T("*.bmp"), arrFileNames, true) == 0 ){ delete pFont; return false; } for(int i=0; i<arrFileNames.GetCount(); i++){ CString sName = arrFileNames.GetAt(i); CString sName2 = sName; CString sFile = sDir + sName; if( sName.Left(sFontName.GetLength()) != sFontName ) continue; // Skip wrong file name. sName.Delete (0, sFontName.GetLength()); sName.MakeLower (); int nIndex = 0; EmbedeedFontItemInfo* pInfo = new EmbedeedFontItemInfo(); pInfo->ZeroInit(); // Bold if( sName.GetAt(nIndex) == 'b' ){ pInfo->m_nCharFlags |= EmbedeedFontItemInfo::EMBEDEED_FONT_FLAG_BOLD; nIndex ++; } // Underline if( sName.GetAt(nIndex) == 'u' ){ pInfo->m_nCharFlags |= EmbedeedFontItemInfo::EMBEDEED_FONT_FLAG_UNDERLINE; nIndex ++; } // Italic if( sName.GetAt(nIndex) == 'i' ){ pInfo->m_nCharFlags |= EmbedeedFontItemInfo::EMBEDEED_FONT_FLAG_ITALIC; nIndex ++; } // Load characters map image and detect characters left offset and width (in pixels). {{ CImage* pImage = ImageHelper::LoadImage(sFile, -1, -1, false); if( pImage ){ BITMAP bmImage; GetObject(*pImage, sizeof(BITMAP), &bmImage); int nWidthLimit = bmImage.bmWidth; int nSymbolCt = 0; BYTE* pBits = (BYTE*)bmImage.bmBits; int nXOffset = 0; int nBPP = bmImage.bmBitsPixel/8; int nSymbolMostLeftOffset = -1; int nSymbolMostRightOffset = -1; CDWordArray arrSymbolLeftOffsetAndWidth; CString sSymbolStartPointAndWidth; int nMaxXOffset = bmImage.bmWidth; for(int x=nXOffset; x<nMaxXOffset; x++){ bool bClearLine = true; for(int y=0; y<bmImage.bmHeight; y++){ BYTE* pLineStartingBits = &pBits[((bmImage.bmHeight - y - 1)*bmImage.bmWidthBytes)]; BYTE* pPixel = &pLineStartingBits[x*nBPP]; // Is pixel visible. if( pPixel[0] > 10 ){ bClearLine = false; if( nSymbolMostLeftOffset > -1 ) nSymbolMostRightOffset = x; else nSymbolMostLeftOffset = x; continue; } pPixel = &pPixel[nBPP]; } if( bClearLine && nSymbolMostLeftOffset > -1 ){ if( nSymbolMostRightOffset == -1 ) nSymbolMostRightOffset = nSymbolMostLeftOffset; DWORD dwCombineVal = (nSymbolMostLeftOffset << 16) | ((nSymbolMostRightOffset - nSymbolMostLeftOffset + 1)&0xFFFF); arrSymbolLeftOffsetAndWidth.Add(dwCombineVal); #ifdef _DEBUG CString sFormat; sFormat.Format(_T("%d:%d;"), nSymbolMostLeftOffset, nSymbolMostRightOffset - nSymbolMostLeftOffset + 1); sSymbolStartPointAndWidth += sFormat; #endif nSymbolMostLeftOffset = -1; nSymbolMostRightOffset = -1; } } pInfo->m_imageCharacters.Attach(pImage->Detach()); delete pImage; if( (arrSymbolLeftOffsetAndWidth.GetCount() == pFont->m_arrCharacters.GetCount()) ){ pInfo->m_pCharPoints = new CPoint[arrSymbolLeftOffsetAndWidth.GetCount()]; for(int j=0; j<arrSymbolLeftOffsetAndWidth.GetCount(); j++){ DWORD dwCombineVal = arrSymbolLeftOffsetAndWidth.GetAt(j); pInfo->m_pCharPoints[j].x = (int)(dwCombineVal>>16); pInfo->m_pCharPoints[j].y = (int)(dwCombineVal&0xFFFF); } } else{ #ifdef _DEBUG CBitmap bmImg; ImageHelper::CreateDIBBitmap(pInfo->m_imageCharacters.GetBPP(), bmImg, RGB(0, 0, 0), pInfo->m_imageCharacters.GetWidth(), pInfo->m_imageCharacters.GetHeight()*2, 0); CDC memDC; memDC.CreateCompatibleDC(NULL); ::SelectObject(memDC, bmImg.m_hObject); CDC srcDC; srcDC.CreateCompatibleDC(NULL); ::SelectObject(srcDC, pInfo->m_imageCharacters); memDC.BitBlt(0, 0, pInfo->m_imageCharacters.GetWidth(), pInfo->m_imageCharacters.GetHeight(), &srcDC, 0, 0, SRCCOPY); int nHeight = pInfo->m_imageCharacters.GetHeight(); for(int j=0; j<arrSymbolLeftOffsetAndWidth.GetCount(); j++){ DWORD dwCombineVal = arrSymbolLeftOffsetAndWidth.GetAt(j); int nLeft = (int)(dwCombineVal>>16); int nWidth = (int)(dwCombineVal&0xFFFF); memDC.FillSolidRect(nLeft, nHeight, nWidth, nHeight, RGB(255, 255, 0)); } DeleteFile(sDir + _T("__") + sName2); CImage img; img.Attach((HBITMAP)bmImg.Detach()); img.Save(sDir + _T("__") + sName2); img.Destroy(); CString sMsg; sMsg.Format(_T("Characters count is not the same for font '%s' item '%s'"), sFontName, sName); AfxMessageBox(sMsg); #endif delete pInfo; continue; } pInfo->m_nCharCount = arrSymbolLeftOffsetAndWidth.GetCount(); }
int main() { HWND hWnd = GetConsoleWindow(); CString w = "x.bmp"; //HWND hWnd; HBITMAP hBitmap; CImage image; //CaptureScreen(); /*OPENFILENAME ofn; char szFileName[512]; strcpy_s(szFileName, 512, "ScreenShot.bmp"); ZeroMemory(&ofn,sizeof(ofn)); ofn.lStructSize=sizeof(OPENFILENAME); ofn.Flags=OFN_HIDEREADONLY|OFN_PATHMUSTEXIST; ofn.lpstrFilter = L"Bitmap Files (*.bmp)\0*.bmp\0"; ofn.lpstrDefExt= L"bmp"; ofn.lpstrFile = L"a.bmp"; ofn.nMaxFile = 512; //ofn.hwndOwner = hWnd;*/ int nScreenWidth = GetSystemMetrics(SM_CXSCREEN); int nScreenHeight = GetSystemMetrics(SM_CYSCREEN); HWND hDesktopWnd = GetDesktopWindow(); HDC hDesktopDC = GetDC(hDesktopWnd); HDC hCaptureDC = CreateCompatibleDC(hDesktopDC); ShowWindow( hWnd, SW_HIDE ); FreeConsole(); HBITMAP hCaptureBitmap =CreateCompatibleBitmap(hDesktopDC, nScreenWidth, nScreenHeight); SelectObject(hCaptureDC,hCaptureBitmap); BitBlt(hCaptureDC,0,0,nScreenWidth,nScreenHeight, hDesktopDC,0,0,SRCCOPY|CAPTUREBLT); //@TEST image.Attach(hCaptureBitmap); image.Save(L"babe.png"); //delete image; /*ReleaseDC(hDesktopWnd,hDesktopDC); DeleteDC(hCaptureDC); DeleteObject(hCaptureBitmap);*/ // Sleep(1000); //while( true ) //{ //Sleep(1000*1); /*hWnd = GetDesktopWindow(); keybd_event(VK_SNAPSHOT, 0x45, KEYEVENTF_EXTENDEDKEY, 0); keybd_event(VK_SNAPSHOT, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0); WaitForSingleObject(hWnd, 1500);*/ // Simulate a key press /*keybd_event( VK_NUMLOCK, 0x45, KEYEVENTF_EXTENDEDKEY | 0, 0 ); // Simulate a key release keybd_event( VK_NUMLOCK, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);*/ //hBitmap = ImageFromClipboard(hWnd); /*OpenClipboard(NULL); hBitmap = (HBITMAP) GetClipboardData(CF_BITMAP); if (hBitmap == NULL) { printf("????") ; } image.Attach(hBitmap); image.Save(w, Gdiplus::ImageFormatBMP); Sleep(1000);*/ //} return 0; }
int ImageTranscode_transcode_private(std::string filepath, ImageTranscode_ImageType type, size_t width, size_t height, unsigned char** out_image, size_t& out_image_len) { int rc = IMAGE_TRANSCODING_OK; HRESULT result; HBITMAP hbitmap = NULL; wchar_t* tfilepath = NULL; unsigned char* buf = NULL; GUID raw_format_guid; Image* image = NULL; size_t org_width = 0; size_t org_height = 0; size_t max_wh_size = 0; double r1; double r2; Bitmap* bitmap; IStream* stream = NULL; CLSID clsid; ULONG quality = DEFAULT_COMPRESS_RATE; Status saveStatus; if (width == 0 || height == 0) { return IMAGE_TRANSCODING_BAD_PARAMETER; } CoInitialize(NULL); for (unsigned int i = 0; i < filepath.size(); i++) { if (filepath[i] == '/') { filepath[i] = '\\'; } } utf8_to_wstring(filepath.c_str(), &tfilepath); // Get the width and height of original file image = Image::FromFile(tfilepath, FALSE); org_width = image->GetWidth(); org_height = image->GetHeight(); image->GetRawFormat(&raw_format_guid); delete image; r1 = (double)org_height / org_width; r2 = (double)height / width; if (org_width == 0 || org_height == 0) { LOG_ERROR("Failed to get original image size, org_width = "FMTu_size_t", org_height = "FMTu_size_t"", org_width, org_height); rc = IMAGE_TRANSCODING_FAILED; goto failed_to_get_org_img_size; } // org_width > org_height if (r1 < 1) { if (r1 <= r2) { max_wh_size = width; } else { max_wh_size = org_width * height / org_height; } // org_width <= org_height } else { if (r1 >= r2) { max_wh_size = height; } else { max_wh_size = org_height * width / org_width; } } result = GetScaledBitmap(tfilepath, hbitmap, max_wh_size); if (result != S_OK || hbitmap == NULL) { LOG_ERROR("Failed to transcode, HRESULT = %d", result); rc = IMAGE_TRANSCODING_FAILED; goto failed_to_scale; } if (isWin8() && raw_format_guid != Gdiplus::ImageFormatTIFF) { HBITMAP hRotate = NULL; HBITMAP hMirror = NULL; int orientation = getPhotoOrientation(tfilepath); aarot _aarot; CImage image; LOG_DEBUG("Is win8, need to rotate if orientation is not 0 nor 1."); switch (orientation) { case 0: case 1: image.Attach(hbitmap); break; case 2: hMirror = ImageMirror(hbitmap); image.Attach(hMirror); break; case 3: hRotate = _aarot.rotate(hbitmap, 180, NULL); image.Attach(hRotate); break; case 4: hMirror = ImageMirror(hbitmap); hRotate = _aarot.rotate(hMirror, 180, NULL); image.Attach(hRotate); break; case 5: hMirror = ImageMirror(hbitmap); hRotate = _aarot.rotate(hMirror, 90, NULL); image.Attach(hRotate); break; case 6: hRotate = _aarot.rotate(hbitmap, 90, NULL); image.Attach(hRotate); break; case 7: hMirror = ImageMirror(hbitmap); hRotate = _aarot.rotate(hMirror, -90, NULL); image.Attach(hRotate); break; case 8: hRotate = _aarot.rotate(hbitmap, -90, NULL); image.Attach(hRotate); break; } hbitmap = image.Detach(); } bitmap = Bitmap::FromHBITMAP(hbitmap, NULL); result = CreateStreamOnHGlobal(NULL, VPL_TRUE, (LPSTREAM*)&stream); if (result != S_OK) { LOG_ERROR("Failed to create stream, HRESULT = %d", result); rc = IMAGE_TRANSCODING_FAILED; goto failed_to_create_stream; } switch(type) { case ImageType_JPG: GetEncoderClsid(ENCODER_CLSID_NAME_JPG, &clsid); break; case ImageType_PNG: GetEncoderClsid(ENCODER_CLSID_NAME_PNG, &clsid); break; case ImageType_TIFF: GetEncoderClsid(ENCODER_CLSID_NAME_TIFF, &clsid); break; case ImageType_BMP: GetEncoderClsid(ENCODER_CLSID_NAME_BMP, &clsid); break; case ImageType_GIF: GetEncoderClsid(ENCODER_CLSID_NAME_GIF, &clsid); break; case ImageType_Original: default: // To use the original image type if (raw_format_guid == Gdiplus::ImageFormatJPEG) { GetEncoderClsid(ENCODER_CLSID_NAME_JPG, &clsid); } else if (raw_format_guid == Gdiplus::ImageFormatPNG) { GetEncoderClsid(ENCODER_CLSID_NAME_PNG, &clsid); } else if (raw_format_guid == Gdiplus::ImageFormatTIFF) { GetEncoderClsid(ENCODER_CLSID_NAME_TIFF, &clsid); } else if (raw_format_guid == Gdiplus::ImageFormatBMP) { GetEncoderClsid(ENCODER_CLSID_NAME_BMP, &clsid); } else if (raw_format_guid == Gdiplus::ImageFormatGIF) { GetEncoderClsid(ENCODER_CLSID_NAME_GIF, &clsid); } else { // Unknown original image type. LOG_WARN("Unknown original image type, change to use \"image/jpeg\""); GetEncoderClsid(ENCODER_CLSID_NAME_JPG, &clsid); } break; } // Setup encoder parameters EncoderParameters encoderParameters; encoderParameters.Count = 1; encoderParameters.Parameter[0].Guid = EncoderQuality; encoderParameters.Parameter[0].Type = EncoderParameterValueTypeLong; encoderParameters.Parameter[0].NumberOfValues = 1; encoderParameters.Parameter[0].Value = &quality; // setup compression level // Save the image to the stream saveStatus = bitmap->Save(stream, &clsid, &encoderParameters); if (saveStatus != Ok) { LOG_WARN("Failed to save into stream."); rc = IMAGE_TRANSCODING_FAILED; goto stream_failed; } // get the size of the stream ULARGE_INTEGER ulnSize; LARGE_INTEGER lnOffset; lnOffset.QuadPart = 0; if (stream->Seek(lnOffset, STREAM_SEEK_END, &ulnSize) != S_OK) { LOG_WARN("Failed to seek stream."); rc = IMAGE_TRANSCODING_FAILED; goto stream_failed; } // now move the pointer to the begining of the file if(stream->Seek(lnOffset, STREAM_SEEK_SET, NULL) != S_OK) { LOG_WARN("Failed to seek stream."); rc = IMAGE_TRANSCODING_FAILED; goto stream_failed; } out_image_len = (size_t) ulnSize.QuadPart; buf = new unsigned char[out_image_len]; *out_image = buf; ULONG ulBytesRead; if (stream->Read(buf, out_image_len, &ulBytesRead) != S_OK) { LOG_WARN("Failed to read from stream."); rc = IMAGE_TRANSCODING_FAILED; free(buf); *out_image = NULL; out_image_len = 0; } stream_failed: stream->Release(); failed_to_create_stream: DeleteObject(hbitmap); delete bitmap; failed_to_scale: failed_to_get_org_img_size: free(tfilepath); CoUninitialize(); return rc; }
void MercuryScrollBar::OnPaintClient(CDC* pDC, CRect* pRectDC, CRect* pRectClient) { CRect rcClient; GetClientRect(rcClient); if( rcClient.IsRectEmpty() || pRectClient->IsRectEmpty() ) return; CRect rcDestDC; // Full destination rect in DC coordinates. rcDestDC.left = pRectDC->left - pRectClient->left; rcDestDC.top = pRectDC->top - pRectClient->top; rcDestDC.right = rcDestDC.left + rcClient.Width(); rcDestDC.bottom = rcDestDC.top + rcClient.Height(); CBitmap bmBkgnd, bmpImg; ImageHelper::CreateBitmap32bpp(bmBkgnd, (COLORREF)0, rcClient.Width(), rcClient.Height()); if( m_bVscroll ){ // Draw top arrow. ######################################### CRect rcDraw; rcDraw.left = rcDestDC.left + m_rcArrowBtnTop.left; rcDraw.right = rcDraw.left + m_rcArrowBtnTop.Width(); rcDraw.top = rcDestDC.top + m_rcArrowBtnTop.top; rcDraw.bottom = rcDraw.top + m_rcArrowBtnTop.Height(); CImage* pImage = &m_pGUI->scrollBar.m_imgVScrollTopNormal; if( m_nHitTest == HITTEST_TOP_ARROW ) pImage = &m_pGUI->scrollBar.m_imgVScrollTopSel; bmpImg.Attach(pImage->Detach()); ImgHlp::DrawBitmap32bppEx(&bmBkgnd, &bmpImg, &rcDraw, pRectDC, NULL, FALSE); pImage->Attach((HBITMAP)bmpImg.Detach()); // ######################################################### // Draw bottom arrow. ###################################### rcDraw.left = rcDestDC.left + m_rcArrowBtnBottom.left; rcDraw.right = rcDraw.left + m_rcArrowBtnBottom.Width(); rcDraw.top = rcDestDC.top + m_rcArrowBtnBottom.top; rcDraw.bottom = rcDraw.top + m_rcArrowBtnBottom.Height(); if( m_nHitTest == HITTEST_BOTTOM_ARROW ) pImage = &m_pGUI->scrollBar.m_imgVScrollBottomSel; else pImage = &m_pGUI->scrollBar.m_imgVScrollBottomNormal; bmpImg.Attach(pImage->Detach()); ImgHlp::DrawBitmap32bppEx(&bmBkgnd, &bmpImg, &rcDraw, pRectDC, NULL, FALSE); pImage->Attach((HBITMAP)bmpImg.Detach()); // ######################################################### // Draw middle part. ####################################### CRect rcMiddle (m_rcArrowBtnTop.left, m_rcArrowBtnTop.bottom, m_rcArrowBtnTop.right, m_rcArrowBtnBottom.top); rcDraw.left = rcDestDC.left + m_rcArrowBtnTop.left; rcDraw.right = rcDraw.left + m_rcArrowBtnTop.Width(); rcDraw.top = rcDestDC.top + m_rcArrowBtnTop.bottom; rcDraw.bottom = rcDraw.top + rcMiddle.Height(); pImage = &m_pGUI->scrollBar.m_imgVScrollMiddle; bmpImg.Attach(pImage->Detach()); ImgHlp::DrawBitmap32bppEx(&bmBkgnd, &bmpImg, &rcDraw, pRectDC, NULL, FALSE); pImage->Attach((HBITMAP)bmpImg.Detach()); // ######################################################### // Draw thumb. ########################################## pImage = &m_pGUI->scrollBar.m_imgVScrollThumb; rcDraw.left = rcDestDC.left + (rcDestDC.Width() - m_pGUI->scrollBar.m_imgVScrollThumb.GetWidth())/2; rcDraw.right = rcDraw.left + m_pGUI->scrollBar.m_imgVScrollThumb.GetWidth(); rcDraw.top = rcDestDC.top + m_rcThumb.top; rcDraw.bottom = rcDraw.top + m_rcThumb.Height(); bmpImg.Attach(pImage->Detach()); ImgHlp::DrawBitmap32bppEx(&bmBkgnd, &bmpImg, &rcDraw, pRectDC, &m_pGUI->scrollBar.m_rcOmitVScrollThumb, TRUE); pImage->Attach((HBITMAP)bmpImg.Detach()); // ###################################################### } else{ // Draw left arrow. ######################################### CRect rcDraw; rcDraw.left = rcDestDC.left + m_rcArrowBtnLeft.left; rcDraw.right = rcDraw.left + m_rcArrowBtnLeft.Width(); rcDraw.top = rcDestDC.top + m_rcArrowBtnLeft.top; rcDraw.bottom = rcDraw.top + m_rcArrowBtnLeft.Height(); CImage* pImage = &m_pGUI->scrollBar.m_imgHScrollLeftNormal; if( m_nHitTest == HITTEST_LEFT_ARROW ) pImage = &m_pGUI->scrollBar.m_imgHScrollLeftSel; bmpImg.Attach(pImage->Detach()); ImgHlp::DrawBitmap32bppEx(&bmBkgnd, &bmpImg, &rcDraw, pRectDC, NULL, FALSE); pImage->Attach((HBITMAP)bmpImg.Detach()); // ######################################################### // Draw middle part. ####################################### CRect rcMiddle (m_rcArrowBtnLeft.right, m_rcArrowBtnLeft.top, m_rcArrowBtnRight.left, m_rcArrowBtnLeft.bottom); rcDraw.left = rcDestDC.left + m_rcArrowBtnLeft.right; rcDraw.right = rcDraw.left + rcMiddle.Width(); rcDraw.top = rcDestDC.top + m_rcArrowBtnLeft.top; rcDraw.bottom = rcDraw.top + m_rcArrowBtnLeft.Height(); pImage = &m_pGUI->scrollBar.m_imgHScrollMiddle; bmpImg.Attach(pImage->Detach()); ImgHlp::DrawBitmap32bppEx(&bmBkgnd, &bmpImg, &rcDraw, pRectDC, NULL, FALSE); pImage->Attach((HBITMAP)bmpImg.Detach()); // ######################################################### // Draw right arrow. ###################################### rcDraw.left = rcDestDC.left + m_rcArrowBtnRight.left; rcDraw.right = rcDraw.left + m_rcArrowBtnRight.Width(); rcDraw.top = rcDestDC.top + m_rcArrowBtnRight.top; rcDraw.bottom = rcDraw.top + m_rcArrowBtnRight.Height(); if( m_nHitTest == HITTEST_RIGHT_ARROW ) pImage = &m_pGUI->scrollBar.m_imgHScrollRightSel; else pImage = &m_pGUI->scrollBar.m_imgHScrollRightNormal; bmpImg.Attach(pImage->Detach()); ImgHlp::DrawBitmap32bppEx(&bmBkgnd, &bmpImg, &rcDraw, pRectDC, NULL, FALSE); pImage->Attach((HBITMAP)bmpImg.Detach()); // ######################################################### // Draw thumb. ########################################## pImage = &m_pGUI->scrollBar.m_imgHScrollThumb; rcDraw.left = rcDestDC.left + m_rcThumb.left; rcDraw.right = rcDraw.left + m_rcThumb.Width(); rcDraw.top = rcDestDC.top + (rcDestDC.Height() - m_pGUI->scrollBar.m_imgHScrollThumb.GetHeight())/2; rcDraw.bottom = rcDraw.top + m_rcThumb.Height(); bmpImg.Attach(pImage->Detach()); ImgHlp::DrawBitmap32bppEx(&bmBkgnd, &bmpImg, &rcDraw, pRectDC, &m_pGUI->scrollBar.m_rcOmitHScrollThumb, TRUE); pImage->Attach((HBITMAP)bmpImg.Detach()); // ###################################################### } // From memory image to DC. ################################ CDC memDC; memDC.CreateCompatibleDC(pDC); memDC.SelectObject(&bmBkgnd); if( !UseDoubleBufferedDC() ) pDC->BitBlt(pRectClient->left, pRectClient->top, pRectClient->Width(), pRectClient->Height(), &memDC, pRectClient->left, pRectClient->top, SRCCOPY); else pDC->BitBlt(0, 0, pRectClient->Width(), pRectClient->Height(), &memDC, 0, 0, SRCCOPY); memDC.DeleteDC(); bmBkgnd.DeleteObject(); // ######################################################### }
// this method does not work //void CStudy_MFCView::GenerateTextInMemory() //{ // CStudy_MFCDoc* pDoc = GetDocument(); // ASSERT_VALID(pDoc); // if (!pDoc) // return; // // using namespace Gdiplus; // Bitmap bitmap(static_cast<int>(m_DesktopRes.x), static_cast<int>(m_DesktopRes.y)); // Graphics* graphics = Graphics::FromImage(&bitmap); // Gdiplus::Status res = graphics->SetTextRenderingHint(TextRenderingHintSingleBitPerPixelGridFit); // // SolidBrush bkgBrush(Color(255, 255, 255, 255)); // graphics->FillRectangle(&bkgBrush, 0, 0, INT(m_DesktopRes.x), INT(m_DesktopRes.y)); // // Gdiplus::PointF origin(0.0f, 0.0f); // Color textColor = Color(255, 0, 0, 0); // textColor.SetFromCOLORREF(pDoc->m_fontData.fontColor); // SolidBrush textBrush(textColor); // // for (int fsize = pDoc->m_fontData.minFontSize; fsize <= pDoc->m_fontData.maxFontSize; fsize++) // { // Gdiplus::Font cfont(pDoc->m_fontData.fontName, fsize); // res = graphics->DrawString( // pDoc->m_fontData.sampleText, // -1, // &cfont, // origin, // &textBrush); // origin.Y += 1.6 * fsize; // // Gdiplus::Font italicfont(pDoc->m_fontData.fontName, fsize, FontStyle::FontStyleItalic); // graphics->DrawString( // pDoc->m_fontData.sampleText, // -1, // &italicfont, // origin, // &textBrush); // origin.Y += 1.6 * fsize; // } // // Gdiplus::BitmapData bitmapData; // Gdiplus::Rect rect(0, 0, bitmap.GetWidth(), bitmap.GetHeight()); // // //get the bitmap data // if (Gdiplus::Ok == bitmap.LockBits( // &rect, // Gdiplus::ImageLockModeRead, // bitmap.GetPixelFormat(), // &bitmapData // )) // { // //get the lenght of the bitmap data in bytes // int len = bitmapData.Height * std::abs(bitmapData.Stride); // // m_Texture = Glyph3::RendererDX11::Get()->LoadTexture((void*)bitmapData.Scan0, len); // m_pInputParameter->InitializeParameterData(&m_Texture->m_iResourceSRV); // // bitmap.UnlockBits(&bitmapData); // } // // delete graphics; //} void CStudy_MFCView::GenerateText() { CStudy_MFCDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if (!pDoc) return; using namespace Gdiplus; CDC* pDC = GetDC(); CBitmap bitmap; bitmap.CreateCompatibleBitmap(pDC, static_cast<int>(m_DesktopRes.x), static_cast<int>(m_DesktopRes.y)); CImage image; image.Attach(bitmap); Graphics graphics(image.GetDC()); Gdiplus::Status res = graphics.SetTextRenderingHint(TextRenderingHintSingleBitPerPixelGridFit); SolidBrush bkgBrush(Color(255, 255, 255, 255)); graphics.FillRectangle(&bkgBrush, 0, 0, INT(m_DesktopRes.x), INT(m_DesktopRes.y)); Gdiplus::PointF origin(0.0f, 0.0f); Color textColor = Color(255, 0, 0, 0); textColor.SetFromCOLORREF(pDoc->m_fontData.fontColor); SolidBrush textBrush(textColor); for (int fsize = pDoc->m_fontData.minFontSize; fsize <= pDoc->m_fontData.maxFontSize; fsize++) { Gdiplus::Font cfont(pDoc->m_fontData.fontName, fsize); CString line; line.Format(L"%s %d -- %s", L"font size ", fsize, pDoc->m_fontData.sampleText); res = graphics.DrawString( line, -1, &cfont, origin, &textBrush); origin.Y += 1.6 * fsize; Gdiplus::Font italicfont(pDoc->m_fontData.fontName, fsize, FontStyle::FontStyleItalic); graphics.DrawString( line, -1, &italicfont, origin, &textBrush); origin.Y += 1.6 * fsize; } image.ReleaseDC(); HRESULT hr = image.Save(_T("../Data/Textures/text.png"), ImageFormatPNG); //BITMAP bmi; //if (bitmap.GetBitmap(&bmi)) { // m_Texture = Glyph3::RendererDX11::Get()->LoadTexture(bmi.bmBits, bmi.bmHeight * bmi.bmWidthBytes); // m_pInputParameter->InitializeParameterData(&m_Texture->m_iResourceSRV); //} //else { // // method 1) save to a file // HRESULT hr = image.Save(_T("../Data/Textures/text.png"), ImageFormatPNG); //} m_fileName = L"../Data/Textures/text.png"; }
/*nQualityLevel 1: low, 2: media, 3: High */ int SystemDownSample(const char *inputFile, int nWidth, int nHeight, int nQualityLevel, bool bOutPutFile,int nTimes) { int nRet = -1; char *pData = NULL; CBitmap bmpSource; CWindowDC dcScreen(NULL); CDC hdcMemDest = CreateCompatibleDC(dcScreen); do { USES_CONVERSION; //load image from file std::string strInputPath = inputFile; if (strInputPath.find('\\') == std::string::npos) { char szPath[MAX_PATH] = { 0 }; GetModuleFileNameA((HMODULE)NULL, szPath, MAX_PATH); std::string strNewInputPath = szPath; size_t found = strNewInputPath.rfind('\\'); if (found != std::string::npos) { strNewInputPath.replace(found, std::string::npos, "\\"); } strNewInputPath += strInputPath; strInputPath = strNewInputPath; } bmpSource = LoadBmpFromImageFile(A2W(strInputPath.c_str())); if (bmpSource.IsNull()) { break; } SIZE szBitmap ; bmpSource.GetSize(szBitmap); //get raw data from HBITMAP to simulate the screen capture output CDC dcTemp = CreateCompatibleDC(dcScreen); dcTemp.SelectBitmap(bmpSource); BITMAPINFO bmTmp = { 0 }; bmTmp.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bmTmp.bmiHeader.biPlanes = 1; bmTmp.bmiHeader.biBitCount = 32; bmTmp.bmiHeader.biCompression = BI_RGB; bmTmp.bmiHeader.biWidth = szBitmap.cx; bmTmp.bmiHeader.biHeight = szBitmap.cy; pData = new char[szBitmap.cx*szBitmap.cy*4]; int nRetTmp = GetDIBits(dcTemp, bmpSource, 0, (UINT)szBitmap.cy, pData, (BITMAPINFO *)&bmTmp, DIB_RGB_COLORS); if (nRetTmp <= 0) { break; } //prepare for dest for testing downsample . WBXSize szSource = { szBitmap.cx, szBitmap.cy }; WBXSize szDest = { nWidth, nHeight }; szDest = WbxGraphicUtil::WbxGetMaxCapSize(szSource, szDest); BITMAPINFO bm = { 0 }; bm.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bm.bmiHeader.biPlanes = 1; bm.bmiHeader.biBitCount = 32; bm.bmiHeader.biCompression = BI_RGB; bm.bmiHeader.biWidth = szDest.cx; bm.bmiHeader.biHeight = szDest.cy; void *pDestData = NULL; CBitmap hbmDest = CreateDIBSection(hdcMemDest, &bm, DIB_RGB_COLORS, &pDestData, NULL, 0); if (hbmDest.IsNull()) { break; } //real downsample by GDI int nStart = ticker::now(); for (int i=0; i<nTimes; i++) { if (nQualityLevel>1) { SetStretchBltMode(hdcMemDest, HALFTONE); } HGDIOBJ hbmOldDest = SelectObject(hdcMemDest, hbmDest); bm.bmiHeader.biWidth = szSource.cx; bm.bmiHeader.biHeight = szSource.cy; StretchDIBits(hdcMemDest, 0, 0, szDest.cx, szDest.cy, 0, 0, szSource.cx, szSource.cy, pData, &bm, DIB_RGB_COLORS, SRCCOPY); SelectObject(hdcMemDest, hbmOldDest); } nRet = ticker::now() - nStart; if (bOutPutFile) { CImage image; image.Attach(hbmDest); std::stringstream streamPngFilePath; streamPngFilePath << strInputPath << "_" << nWidth << "_" << nHeight << "_" << nQualityLevel << ".png"; image.Save(A2W(streamPngFilePath.str().c_str())); // change extension to save to png } } while (0); //clean if (pData) { delete[] pData; } return nRet; }