当前位置:网站首页>Display opencv drawn pictures on MFC picture control control
Display opencv drawn pictures on MFC picture control control
2022-07-04 17:17:00 【Eight to】
// take picture control Control type Type set to bitmap Bitmp Format
// Format the picture so that it can be correctly displayed on the control
void CMFCApplication1Dlg::OnBnClickedButton2()
{
CRect rect;
GetDlgItem(IDC_STATIC110)->GetClientRect(&rect); // obtain picture control Control size ( Control ID:IDC_STATIC110)
double mult1 = 0.0, mult2 = 0.0;
cv::Size mults_size(imgTmp.size());//imgTmp by opencv Drawing pictures
if (rect.Width() < imgTmp.size().width)// Convert the image display scale according to the window size , Ensure that the picture is completely displayed
{
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);// The zoom
// Transformation format
switch (imgTmp.channels())
{
case 1:
cv::cvtColor(imgTmp, imgTmp, CV_GRAY2BGRA); // GRAY single channel
break;
case 3:
cv::cvtColor(imgTmp, imgTmp, CV_BGR2BGRA); // BGR Three channels
break;
default:
break;
}
int pixelBytes = imgTmp.channels()*(imgTmp.depth() + 1); // Calculate the number of bytes of a pixel
// Make bitmapinfo( Data header )
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' ( In the above formula biWidth’ Must be 4 Integer multiple ( No biWidth, It is biWidth’, Is greater than or equal to biWidth Of , Nearest 4 Integer multiple . for instance , If biWidth=240, be biWidth’=240; If biWidth=241,biWidth’=244). )
bitInfo.bmiHeader.biXPelsPerMeter = 0;// Is the number of pixels per meter in the real world Set to 3780 that will do
bitInfo.bmiHeader.biYPelsPerMeter = 0;
// Mat.data + bitmap Data header -> 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);
}
边栏推荐
- 整理混乱的头文件,我用include what you use
- 表单传递时,如何隐式将值传过去
- 2022年国内云管平台厂商哪家好?为什么?
- Object.keys()的用法
- Object. Usage of keys()
- GO开发:如何利用Go单例模式保障流媒体高并发的安全性?
- ble HCI 流控机制
- Overflow: the combination of auto and Felx
- Understand ThreadLocal in one picture
- Difference between redis' memory obsolescence strategy and expiration deletion strategy
猜你喜欢

VMware Tools和open-vm-tools的安装与使用:解决虚拟机不全屏和无法传输文件的问题

Position encoding practice in transformer

Chow Tai Fook fulfills the "centenary commitment" and sincerely serves to promote green environmental protection

OPPO小布推出预训练大模型OBERT,晋升KgCLUE榜首

程序员怎么才能提高代码编写速度?

智慧物流园区供应链管理系统解决方案:数智化供应链赋能物流运输行业供应链新模式

NoSQL之readis配置与优化(终章)

MVC模式和三层架构

世界环境日 | 周大福用心服务推动减碳环保

利用win10计划任务程序定时自动运行jar包
随机推荐
7 RSA密码体制
Li Kou today's question -1200 Minimum absolute difference
What grade does Anxin securities belong to? Is it safe to open an account
Capvision Rongying's prospectus in Hong Kong was "invalid": it was strictly questioned by the CSRC and required supplementary disclosure
一加10 Pro和iPhone 13怎么选?
2022PMP考试基本情况详情了解
Go language loop statement (under Lesson 10)
时序图数据建模与产业链分析
[acwing] 58 weeks 4490 dyeing
Object.keys()的用法
APOC custom functions and procedures
长城证券开户安全吗 证券账户怎么开通
Array filter fliter in JS
Visual Studio 2019 (LocalDB)MSSQLLocalDB SQL Server 2014 数据库版本为852无法打开,此服务器支持782
The test experience "tortured" by the PMP test is worth your review
基于check-point机制的任务状态回滚和数据分块任务
祝贺Artefact首席数据科学家张鹏飞先生荣获 Campaign Asia Tech MVP 2022
Inside and outside: flow chart drawing elementary: six common mistakes
System. Currenttimemillis() and system Nanotime (), which is faster? Don't use it wrong!
照明行业S2B2B解决方案:高效赋能产业供应链,提升企业经济效益