当前位置:网站首页>将Opencv绘制图片显示在MFC Picture Control控件上
将Opencv绘制图片显示在MFC Picture Control控件上
2022-07-04 15:25:00 【八至】
//将picture control控件type类型设置为位图Bitmp格式
//对图片进行格式转换使其能正确显示在控件上
void CMFCApplication1Dlg::OnBnClickedButton2()
{
CRect rect;
GetDlgItem(IDC_STATIC110)->GetClientRect(&rect); // 获取picture control控件大小(控件ID:IDC_STATIC110)
double mult1 = 0.0, mult2 = 0.0;
cv::Size mults_size(imgTmp.size());//imgTmp为opencv绘制图片
if (rect.Width() < imgTmp.size().width)//根据窗口大小转换图片显示比例,保证图片完整显示
{
mults_size.width = rect.Width();
mult1 = (double)rect.Width() / (double)imgTmp.size().width;
mults_size.height = imgTmp.size().height * mult1;
}
if (rect.Height() < imgTmp.size().height)
{
mult2 = (double)rect.Height() / (double)mults_size.height;
mults_size.width = mults_size.width * mult2;
mults_size.height = rect.Height();
}
cv::resize(imgTmp, imgTmp, mults_size);// 缩放
// 转换格式
switch (imgTmp.channels())
{
case 1:
cv::cvtColor(imgTmp, imgTmp, CV_GRAY2BGRA); // GRAY单通道
break;
case 3:
cv::cvtColor(imgTmp, imgTmp, CV_BGR2BGRA); // BGR三通道
break;
default:
break;
}
int pixelBytes = imgTmp.channels()*(imgTmp.depth() + 1); // 计算一个像素多少个字节
// 制作bitmapinfo(数据头)
BITMAPINFO bitInfo;
bitInfo.bmiHeader.biBitCount = 8 * pixelBytes;
bitInfo.bmiHeader.biWidth = imgTmp.cols;
bitInfo.bmiHeader.biHeight = -imgTmp.rows;
bitInfo.bmiHeader.biPlanes = 1;
bitInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bitInfo.bmiHeader.biCompression = BI_RGB;
bitInfo.bmiHeader.biClrImportant = 0;
bitInfo.bmiHeader.biClrUsed = 0;
bitInfo.bmiHeader.biSizeImage = 0;// biWidth' * biHeight' * biBitCount' (上述公式中的biWidth’必须是4的整倍数(不是biWidth,而是biWidth’,表示大于或等于biWidth的,最接近4的整倍数。举个例子,如果biWidth=240,则biWidth’=240;如果biWidth=241,biWidth’=244)。 )
bitInfo.bmiHeader.biXPelsPerMeter = 0;//是现实世界中每米包含的像素数 设为3780即可
bitInfo.bmiHeader.biYPelsPerMeter = 0;
// Mat.data + bitmap数据头 -> MFC
CDC *pDC = GetDlgItem(IDC_STATIC110)->GetDC();
::StretchDIBits(
pDC->GetSafeHdc(),
0, 0, rect.Width(), rect.Height(),
0, 0, rect.Width(), rect.Height(),
imgTmp.data,
&bitInfo,
DIB_RGB_COLORS,
SRCCOPY
);
ReleaseDC(pDC);
}
边栏推荐
- 基于check-point实现图数据构建任务
- 时序图数据建模与产业链分析
- Visual Studio 2019 (LocalDB)MSSQLLocalDB SQL Server 2014 数据库版本为852无法打开,此服务器支持782
- Understand ThreadLocal in one picture
- 跳跃表实例
- 线性时间排序
- Implement graph data construction task based on check point
- ECCV 2022 released: 1629 papers were selected, and the employment rate was less than 20%
- VMware Tools和open-vm-tools的安装与使用:解决虚拟机不全屏和无法传输文件的问题
- Research Report on market supply and demand and strategy of China's well completion equipment industry
猜你喜欢
昆明三环闭合工程将经过这些地方,有在你家附近的吗?
Go micro tutorial - Chapter 2 go micro V3 using gin and etcd
建筑建材行业经销商协同系统解决方案:赋能企业构建核心竞争力
DC-2靶场搭建及渗透实战详细过程(DC靶场系列)
祝贺Artefact首席数据科学家张鹏飞先生荣获 Campaign Asia Tech MVP 2022
Overflow: the combination of auto and Felx
Can you really use MySQL explain?
Embedded software architecture design - function call
Position encoding practice in transformer
Kunming Third Ring Road Closure project will pass through these places. Is there one near your home?
随机推荐
The test experience "tortured" by the PMP test is worth your review
Array filter fliter in JS
China tall oil fatty acid market trend report, technical dynamic innovation and market forecast
Overflow: the combination of auto and Felx
智慧物流園區供應鏈管理系統解决方案:數智化供應鏈賦能物流運輸行業供應鏈新模式
力扣今日题-1200. 最小绝对差
安信证券排名 网上开户安全吗
Research Report on market supply and demand and strategy of China's well completion equipment industry
51 single chip microcomputer temperature alarm based on WiFi control
FIREBIRD使用经验总结
How to "use" Perl modules in directories that are not in @inc- How do I 'use' a Perl module in a directory not in @INC?
多年锤炼,迈向Kata 3.0 !走进开箱即用的安全容器体验之旅| 龙蜥技术
整理混乱的头文件,我用include what you use
APOC自定义函数和过程
Readis configuration and optimization of NoSQL (final chapter)
How to contribute to the source code of ongdb core project
Linear time sequencing
矿产行业商业供应链协同系统解决方案:构建数智化供应链平台,保障矿产资源安全供应
话里话外:流程图绘制初级:六大常见错误
Firebird experience summary