简单的MFC在Picture控件上放大缩小图像,显示时:缩小功能正常,放大功能有问题
2016-11-30 14:50
459 查看
//载入原始图 Mat srcImage = imread("D:\\1.bmp",1); //工程目录下应该有一张名为1.jpg的素材图 Mat tmpImage,dstImage1,dstImage2;//临时变量和目标图的定义 tmpImage=srcImage;//将原始图赋给临时变量 float up=6; resize(tmpImage,dstImage1,Size(tmpImage.cols/up,tmpImage.rows/up),(0,0),(0,0),3); resize(tmpImage,dstImage2,Size(tmpImage.cols*up,tmpImage.rows*up),(0,0),(0,0),3); imwrite("D:\\2.bmp",dstImage1); imwrite("D:\\3.bmp",dstImage2); int height, width; CRect rect;//定义矩形类 CRect rect1; CImage image; //创建图片类 CString imgPath; imgPath="D:\\3.bmp"; image.Load(imgPath); height = image.GetHeight(); width = image.GetWidth(); m_pic.GetClientRect(&rect); //获得pictrue控件所在的矩形区域 CDC *pDc = m_pic.GetDC();//获得pictrue控件的Dc SetStretchBltMode(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控件表示的矩形区域 } 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控件的Dc
相关文章推荐
- OpenCV学习笔记(9)利用MFC的Picture控件显示图像+播放视频和捕获摄像头画面
- 利用MFC的Picture控件显示和处理图像
- 将Mat图像显示到MFC PictureControl控件上
- OpenCV 利用MFC的Picture控件显示和处理图像
- OpenCV学习笔记(9)利用MFC的Picture控件显示图像+播放视频和捕获摄像头画面
- OpenCV如何把图像显示到MFC的picture控件上
- MFC中picture控件中利用OpenCV显示图像
- OpenCV学习笔记(9)利用MFC的Picture控件显示图像+播放视频和捕获摄像头画面
- OpenCV学习 利用MFC的Picture控件显示图像+播放视频和捕获摄像头画面
- OpenCV 利用MFC的Picture控件显示和处理图像
- MFC—PictureControl控件使用,显示和处理图像
- 利用MFC的Picture控件显示和处理图像
- OpenCV导入图像显示到MFC的PICTURE控件
- 【OpenCV+MFC】之一:在Picture控件显示图像
- OpenCV 利用MFC的Picture控件显示和处理图像
- OpenCV 利用MFC的Picture控件显示和处理图像
- 利用MFC的Picture控件显示和处理图像
- MFC对话框的picture控件中显示IplImage*格式图像
- Halcon MFC混合编程-图像显示随鼠标滚动放大缩小
- Halcon MFC混合编程-图像显示随鼠标滚动放大缩小