I don’t see the need for CImage new_image (since SetBitmap accepts HBITMAP, which you already have via pb), and pb and pMDC should be removed (after disconnecting HBITMAP), but for the rest this seems correct.
CImage img1;
int dimx = 100, dimy = 100;
img1.Load(filename);
//filename = path on local system to the bitmap
CDC *screenDC = GetDC();
CDC mDC;
mDC.CreateCompatibleDC(screenDC);
CBitmap b;
b.CreateCompatibleBitmap(screenDC, dimx, dimy);
CBitmap *pob = mDC.SelectObject(&b);
mDC.SetStretchBltMode(HALFTONE);
img1.StretchBlt(mDC.m_hDC, 0, 0, dimx, dimy, 0, 0, img1.GetWidth(), img1.GetHeight(), SRCCOPY);
mDC.SelectObject(pob);
m_pictureCtrl.SetBitmap((HBITMAP)b.Detach());
ReleaseDC(screenDC);
Of course, I would put the CImage / CBitmap scaling in a separate function (make it reusable).
source
share