当前位置:网站首页>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);
}
边栏推荐
- NFT流动性市场安全问题频发—NFT交易平台Quixotic被黑事件分析
- Which domestic cloud management platform manufacturer is good in 2022? Why?
- Visual studio 2019 (localdb) mssqllocaldb SQL Server 2014 database version is 852 and cannot be opened. This server supports 782
- Rebalance operation in spark and its difference from repartition operation
- 容器环境minor gc异常频繁分析
- 基于wifi控制的51单片机温度报警器
- FIREBIRD使用经验总结
- Li Kou today's question -1200 Minimum absolute difference
- To sort out messy header files, I use include what you use
- SQL implements split
猜你喜欢

如何实现一个延时队列 ?

How to choose one plus 10 pro and iPhone 13?

The 18th IET AC / DC transmission International Conference (acdc2022) was successfully held online

Which domestic cloud management platform manufacturer is good in 2022? Why?

Blood spitting finishing nanny level series tutorial - play Fiddler bag grabbing tutorial (2) - first meet fiddler, let you have a rational understanding

容器环境minor gc异常频繁分析

周大福践行「百周年承诺」,真诚服务推动绿色环保

How to implement a delay queue?

NFT流动性市场安全问题频发—NFT交易平台Quixotic被黑事件分析

C# 更加优质的操作MongoDB数据库
随机推荐
Summary of tx.origin security issues
Visual studio 2019 (localdb) mssqllocaldb SQL Server 2014 database version is 852 and cannot be opened. This server supports 782
智慧物流園區供應鏈管理系統解决方案:數智化供應鏈賦能物流運輸行業供應鏈新模式
【模板】【luogu P4630】Duathlon 铁人两项(圆方树)
中信证券网上开户安全吗 开户收费吗
. Net applications consider x64 generation
矿产行业商业供应链协同系统解决方案:构建数智化供应链平台,保障矿产资源安全供应
Web game engine
《吐血整理》保姆级系列教程-玩转Fiddler抓包教程(2)-初识Fiddler让你理性认识一下
Firebird experience summary
NFT流动性市场安全问题频发—NFT交易平台Quixotic被黑事件分析
7 RSA密码体制
How to implement a delay queue?
[Acwing] 58周赛 4490. 染色
Is it safe for Anxin securities to open an account online? Is the account opening fee charged
C# 更加优质的操作MongoDB数据库
OPPO小布推出预训练大模型OBERT,晋升KgCLUE榜首
FIREBIRD使用经验总结
51 single chip microcomputer temperature alarm based on WiFi control
新的职业已经出现,怎么能够停滞不前 ,人社部公布建筑新职业