Scaling a bitmap in a static picture

  • Thread starter Thread starter Gregary
  • Start date Start date
G

Gregary

Guest
For god sake


Surely there must be a SIMPLE way to get a bitmap (loaded from a file) to fit within a static picture control?


How??


This is the code I have that successfully puts the bitmap into the static control. But I can't find any way (that works for me) to scale the bitmap.


void CGregsLaserEngraverDlg::LoadBitmap()
{
if (!m_strFilename.IsEmpty())
{
CBitmap bmp;
HBITMAP hBitmap = (HBITMAP)::LoadImage(AfxGetInstanceHandle(), m_strFolder + "\\" + m_strFilename, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION | LR_DEFAULTSIZE | LR_VGACOLOR);
bmp.Attach(hBitmap);
m_staticBMP.SetBitmap(bmp);

BITMAP bitmap;
bmp.GetBitmap(&bitmap);

UpdateData(false);
}
}




I have tried this sort of thing but it has not effect what so ever on the displayed bitmap:

CDC *pDC = GetDC(), dc;
CRect rect;
CBitmap bmpScaled, *pBMPScaled = NULL;

m_staticBMP.GetClientRect(rect);
dc.CreateCompatibleDC(pDC);
bmpScaled.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height());
pBMPScaled = dc.SelectObject(&bmpScaled);
dc.StretchBlt(0, 0, rect.Width(), rect.Height(), &dc, 0, 0, bitmap.bmWidth, bitmap.bmHeight, SRCCOPY);
//dc.SelectObject(pob);
//Bitmap_.SetBitmap((HBITMAP)scale_bitmap.Detach());
ReleaseDC(pDC);

Continue reading...
 
Back
Top