当前位置:网站首页>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);
}
边栏推荐
- Capvision Rongying's prospectus in Hong Kong was "invalid": it was strictly questioned by the CSRC and required supplementary disclosure
- Smart Logistics Park supply chain management system solution: digital intelligent supply chain enables a new supply chain model for the logistics transportation industry
- Firebird experience summary
- Use and principle of thread pool
- overflow:auto与felx结合的用法
- Rebalance operation in spark and its difference from repartition operation
- Embedded software architecture design - function call
- Go语言循环语句(第10课下)
- TP configuring multiple databases
- The 18th IET AC / DC transmission International Conference (acdc2022) was successfully held online
猜你喜欢
Can you really use MySQL explain?
整理混乱的头文件,我用include what you use
C# 更加优质的操作MongoDB数据库
Chow Tai Fook fulfills the "centenary commitment" and sincerely serves to promote green environmental protection
DataKit——真正的统一可观测性 Agent
How can programmers improve the speed of code writing?
太方便了,钉钉上就可完成代码发布审批啦!
51 single chip microcomputer temperature alarm based on WiFi control
The Ministry of human resources and Social Security announced the new construction occupation
世界环境日 | 周大福用心服务推动减碳环保
随机推荐
话里话外:流程图绘制初级:六大常见错误
Is it safe for Anxin securities to open an account online? Is the account opening fee charged
【云原生】服务网格是什么“格”?
如何为ONgDB核心项目源码做贡献
Capvision Rongying's prospectus in Hong Kong was "invalid": it was strictly questioned by the CSRC and required supplementary disclosure
利用win10计划任务程序定时自动运行jar包
NFT liquidity market security issues occur frequently - Analysis of the black incident of NFT trading platform quixotic
Difference between redis' memory obsolescence strategy and expiration deletion strategy
Why do you say that the maximum single table of MySQL database is 20million? Based on what?
Leetcode list summary
Load test practice of pingcode performance test
What grade does Anxin securities belong to? Is it safe to open an account
力扣今日题-1200. 最小绝对差
[Acwing] 58周赛 4489. 最长子序列
Is it safe for CITIC Securities to open an account online? Is the account opening fee charged
表单传递时,如何隐式将值传过去
Object.keys()的用法
How can programmers improve the speed of code writing?
PingCode 性能测试之负载测试实践
OPPO小布推出预训练大模型OBERT,晋升KgCLUE榜首