C++ 图片自适应 picture control 控件大小 不失真显示

来源:互联网 发布:易名域名 编辑:程序博客网 时间:2024/06/05 04:20

原文地址:http://blog.sina.com.cn/s/blog_69b5d2a50101a7qf.html


bool CFlapContrlDlg::Show_picture(CString imgPath){int height, width;CRect rect;//定义矩形类CRect rect1;CImage image; //创建图片类image.Load(imgPath);height = image.GetHeight();width = image.GetWidth();m_PictureControl.GetClientRect(&rect); //获得pictrue控件所在的矩形区域CDC *pDc = m_PictureControl.GetDC();//获得pictrue控件的DcSetStretchBltMode(pDc->m_hDC,STRETCH_HALFTONE); if(width<=rect.Width() && height<=rect.Width()) //小图片,不缩放{rect1 = CRect(rect.TopLeft(), CSize(width,height));image.StretchBlt(pDc->m_hDC,rect1,SRCCOPY); //将图片画到Picture控件表示的矩形区域return TRUE;}else{float xScale=(float)rect.Width()/(float)width;float yScale=(float)rect.Height()/(float)height;float ScaleIndex=(xScale>=yScale:xScale,yScale);rect1 = CRect(rect.TopLeft(), CSize((int)width*ScaleIndex,(int)height*ScaleIndex));image.StretchBlt(pDc->m_hDC,rect1,SRCCOPY); //将图片画到Picture控件表示的矩形区域}ReleaseDC(pDc);//释放picture控件的Dcreturn TRUE;

1 0
原创粉丝点击