当前位置:网站首页>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);
}
边栏推荐
- tp配置多数据库
- 网页游戏引擎
- 中信证券网上开户安全吗 开户收费吗
- 高度剩余法
- Congratulations to Mr. Zhang Pengfei, chief data scientist of artefact, for winning the campaign Asia tech MVP 2022
- Spark 中的 Rebalance 操作以及与Repartition操作的区别
- Load test practice of pingcode performance test
- 程序员怎么才能提高代码编写速度?
- 照明行业S2B2B解决方案:高效赋能产业供应链,提升企业经济效益
- NFT流动性市场安全问题频发—NFT交易平台Quixotic被黑事件分析
猜你喜欢

【Unity UGUI】ScrollRect 动态缩放格子大小,自动定位到中间的格子

矿产行业商业供应链协同系统解决方案:构建数智化供应链平台,保障矿产资源安全供应

利用win10计划任务程序定时自动运行jar包

聊聊异步编程的 7 种实现方式

kaili不能输入中文怎么办???

Object. Usage of keys()

基于wifi控制的51单片机温度报警器

Congratulations to Mr. Zhang Pengfei, chief data scientist of artefact, for winning the campaign Asia tech MVP 2022

go-micro教程 — 第二章 go-micro v3 使用Gin、Etcd

第十八届IET交直流输电国际会议(ACDC2022)于线上成功举办
随机推荐
Can you really use MySQL explain?
NFT liquidity market security issues occur frequently - Analysis of the black incident of NFT trading platform quixotic
overflow:auto与felx结合的用法
力扣今日题-1200. 最小绝对差
Oracle监听器Server端与Client端配置实例
Chow Tai Fook fulfills the "centenary commitment" and sincerely serves to promote green environmental protection
电子元器件B2B商城系统开发:赋能企业构建进销存标准化流程实例
js中的数组筛选fliter
tx.origin安全问题总结
安信证券手机版下载 网上开户安全吗
Years of training, towards Kata 3.0! Enter the safe container experience out of the box | dragon lizard Technology
Understand Alibaba cloud's secret weapon "dragon architecture" in the article "science popularization talent"
表单传递时,如何隐式将值传过去
What grade does Anxin securities belong to? Is it safe to open an account
Hash table
How to implicitly pass values when transferring forms
[acwing] 58 weeks 4489 Longest subsequence
Jump table instance
Cypher task design and task locking mechanism of isomorphic and heterogeneous graphs
Load test practice of pingcode performance test