Click here to Skip to main content
15,849,494 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi all,

I use MFC to create a dialog base application. I load a bitmap into picture box in dialog. When I change dpi of windows so bitmap don't resize.

So fixing this problem. I use code as bellow:
C++
double scale = afxGlobalData.GetRibbonImageScale();
CImage img1;
img1.LoadFromResource(AfxGetInstanceHandle(), IDB_BITMAP1);

int dimx = img1.GetWidth()*scale;
int dimy = img1.GetHeight()*scale;

CDC *pDC = GetDC();
CDC mDC;
mDC.CreateCompatibleDC(pDC);
CBitmap scale_bitmap;
scale_bitmap.CreateCompatibleBitmap(pDC, dimx, dimy);

CBitmap *pob = mDC.SelectObject(&scale_bitmap);
img1.StretchBlt(mDC.m_hDC, 0, 0, dimx, dimy, 0, 0, img1.GetWidth(), img1.GetHeight(), SRCCOPY);
mDC.SelectObject(pob);
Bitmap_.SetBitmap((HBITMAP)scale_bitmap.Detach());
ReleaseDC(pDC);


My bitmap is resized but size of bitmap is incorrect.
examble : dpi = 125% size of bitmap is incorect.

can members help for me ?
Thanks
Posted
Updated 6-Nov-12 5:57am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900