MFC在CStatic中显示图片

来源:互联网 发布:股票网络投票什么意思 编辑:程序博客网 时间:2024/05/23 12:09
                       CRect rect;
GetClientRect(&rect);//显示图片的客户端区域
CBitmap bitmap;
HBITMAP hmap;

hmap = (HBITMAP)LoadImage(NULL,image_path,IMAGE_BITMAP,rect.Width(),rect.Height(),LR_LOADFROMFILE);


bitmap.Attach(hmap);
BITMAP bmp;
//bitmap.GetBitmap(&bmp);
bitmap.GetObject(sizeof(bmp), &bmp);


CDC dcCompatible;
dcCompatible.CreateCompatibleDC(pDC);


dcCompatible.SelectObject(&bitmap);
pDC->SetStretchBltMode(COLORONCOLOR);////设置在指定设备内容中的伸张模式,解决失真问题


pDC->StretchBlt(0,0,rect.Width(),rect.Height(),&dcCompatible,0,0,
rect.Width()*bmp.bmHeight/rect.Height(),bmp.bmWidth*rect.Height()/rect.Width(),SRCCOPY);
0 0
原创粉丝点击