请问如何使图片动态适应picture控件的尺寸,谢谢

lj1006 2008-06-11 02:41:50
之前有定义:HBITMAP m_hPhotoBitmap;
void CView0::DrawUserPhoto(int x, int y, CDC *pDC)
{
if(!m_hPhotoBitmap) return;

HBITMAP OldBitmap;

CWnd *pWnd = GetDlgItem(IDC_PICTURE);
CRect rect;
pWnd->GetClientRect(&rect);
pDC = pWnd->GetDC();

CDC MemDC;

MemDC.CreateCompatibleDC(pDC);
OldBitmap=(HBITMAP)MemDC.SelectObject(m_hPhotoBitmap);

pDC->BitBlt(x,y,rect.Width(),rect.Height(),&MemDC,0,0,SRCCOPY);
MemDC.SelectObject(OldBitmap);
}
void CView0::OnPaint()
{
CPaintDC dc(this); // device context for painting

if (IsIconic())
{
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;

// Draw the icon
//dc.DrawIcon(x, y, m_hIcon);
}
else
{
CWnd *pWnd = GetDlgItem(IDC_PICTURE);
CRect rect;
pWnd->GetClientRect(&rect);
DrawUserPhoto(rect.left,rect.top,&dc);
CView::OnPaint();
}
}

这样写后,控件之外的图片就显示不全了,请问改怎么改啊,谢谢
...全文
271 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
izardMan 2008-06-11
  • 打赏
  • 举报
回复
Attach
lj1006 2008-06-11
  • 打赏
  • 举报
回复
error C2039: 'attach' : is not a member of 'CBitmap'怎么不对啊
izardMan 2008-06-11
  • 打赏
  • 举报
回复
CBitmap bitmap;
BITMAP bmp;
bitmap.attach(hbitmap);
bmp.GetBitmap(&bmp);
bmp.bmHeight;
bmp.bmWidth;
lj1006 2008-06-11
  • 打赏
  • 举报
回复
StretchBlt中的 int nSrcWidth, int nSrcHeight如何得到啊
lj1006 2008-06-11
  • 打赏
  • 举报
回复
哦,明白一些了,图片的高、宽如何得到啊
lj1006 2008-06-11
  • 打赏
  • 举报
回复
请问在我的程序中如何使用StretchBlt呢,小弟初学不是很明白,谢谢
zjw6861982 2008-06-11
  • 打赏
  • 举报
回复
BOOL StretchBlt(int x, int y, int nWidth, int nHeight, CDC* pSrcDC,
int xSrc, int ySrc, int nSrcWidth, int nSrcHeight, DWORD dwRop);
lj1006 2008-06-11
  • 打赏
  • 举报
回复
请问stretchblt怎么用啊
na_he 2008-06-11
  • 打赏
  • 举报
回复
没错的,stretchblt
ouyh12345 2008-06-11
  • 打赏
  • 举报
回复
StretchBlt
blwinner 2008-06-11
  • 打赏
  • 举报
回复
stretchblt
blwinner 2008-06-11
  • 打赏
  • 举报
回复
把bitblt换成strctchblt,这个函数会放大缩小图片自适应控件大小

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧