将Mat图片加载到PictureControl控件中
2016-03-26 09:45
183 查看
//将Mat图片加载到PictureControl控件中,CWnd* pWnd为PictureControl的句柄
void CModelViewControllerDlg::showMatImgToWnd(CWnd* pWnd, const cv::Mat& img)
{
if(img.empty())
return;
static BITMAPINFO *bitMapinfo = NULL;
static bool First=TRUE;
if(First)
{
BYTE *bitBuffer = new BYTE[40+4*256];//开辟一个内存区域
if(bitBuffer == NULL)
{
return;
}
First=FALSE;
memset(bitBuffer, 0, 40+4*256);
bitMapinfo = (BITMAPINFO *)bitBuffer;
bitMapinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bitMapinfo->bmiHeader.biPlanes = 1;
for(int i=0; i<256; i++)
{ //颜色的取值范围 (0-255)
bitMapinfo->bmiColors[i].rgbBlue =bitMapinfo->bmiColors[i].rgbGreen =bitMapinfo->bmiColors[i].rgbRed =(BYTE) i;
}
}
bitMapinfo->bmiHeader.biHeight = -img.rows;
bitMapinfo->bmiHeader.biWidth = img.cols;
bitMapinfo->bmiHeader.biBitCount= img.channels() *8;
CRect drect;
pWnd->GetClientRect(drect); //pWnd指向CWnd类的一个指针
CClientDC dc(pWnd);
HDC hDC =dc.GetSafeHdc(); //HDC是Windows的一种数据类型,是设备描述句柄;
SetStretchBltMode(hDC, COLORONCOLOR);
StretchDIBits(hDC,
0,
0,
drect.right, //显示窗口宽度
drect.bottom, //显示窗口高度
0,
0,
img.cols, //图像宽度
img.rows, //图像高度
img.data,
bitMapinfo,
DIB_RGB_COLORS,
SRCCOPY);
}
void CModelViewControllerDlg::showMatImgToWnd(CWnd* pWnd, const cv::Mat& img)
{
if(img.empty())
return;
static BITMAPINFO *bitMapinfo = NULL;
static bool First=TRUE;
if(First)
{
BYTE *bitBuffer = new BYTE[40+4*256];//开辟一个内存区域
if(bitBuffer == NULL)
{
return;
}
First=FALSE;
memset(bitBuffer, 0, 40+4*256);
bitMapinfo = (BITMAPINFO *)bitBuffer;
bitMapinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bitMapinfo->bmiHeader.biPlanes = 1;
for(int i=0; i<256; i++)
{ //颜色的取值范围 (0-255)
bitMapinfo->bmiColors[i].rgbBlue =bitMapinfo->bmiColors[i].rgbGreen =bitMapinfo->bmiColors[i].rgbRed =(BYTE) i;
}
}
bitMapinfo->bmiHeader.biHeight = -img.rows;
bitMapinfo->bmiHeader.biWidth = img.cols;
bitMapinfo->bmiHeader.biBitCount= img.channels() *8;
CRect drect;
pWnd->GetClientRect(drect); //pWnd指向CWnd类的一个指针
CClientDC dc(pWnd);
HDC hDC =dc.GetSafeHdc(); //HDC是Windows的一种数据类型,是设备描述句柄;
SetStretchBltMode(hDC, COLORONCOLOR);
StretchDIBits(hDC,
0,
0,
drect.right, //显示窗口宽度
drect.bottom, //显示窗口高度
0,
0,
img.cols, //图像宽度
img.rows, //图像高度
img.data,
bitMapinfo,
DIB_RGB_COLORS,
SRCCOPY);
}
相关文章推荐
- 中国科学院图书馆分类法
- C&&C++ 经典书籍
- 中国科学院图书馆分类法
- POJ 1611 The Suspects
- vi跳刀最后一行
- android Fragment与Activity交互,互相发数据(附图详解)
- win10不能启动apache该怎么解决?
- mysql命令一些常用的选项
- poj1815
- nginx安装和配置
- 数据库关于group by 两个或以上条件的分析
- apache camel 条件路由
- 给键盘添加一个工具条
- html页面中查找元素 css
- 运算符
- 线程间的通信
- cjson源码剖析(1)
- MySQL数据库MyISAM和InnoDB存储引擎的比较
- Educational Codeforces Round 3 C. Load Balancing
- UIScrollView的delaysContentTouches与canCencelContentTouches属性