使用Window的DC把OpenCV读入的图像数据绘制出来
2010-02-01 17:05
465 查看
使用Window的DC把OpenCV读入的图像数据绘制出来
http://blog.csdn.net/hardVB/archive/2007/04/23/1575349.aspx
void OpenVCLoadPicture()
{
IplImage* pImg;
CString strPathName;
CFileDialog dlg(TRUE);
CDC* pDC = this->GetDC();
CRect rect;
this->GetClientRect(&rect);
if(dlg.DoModal()==IDOK)
{
strPathName = dlg.GetPathName();
// 加载一幅图片
pImg = cvLoadImage(strPathName);
BITMAPINFO bmi;
FillBitmapInfo(&bmi,pImg->width,pImg->height,(pImg->depth)*(pImg->nChannels));
// DC中绘制
::StretchDIBits(pDC->GetSafeHdc(), rect.left, rect.top, pImg->width, pImg->height, 0, 0,
pImg->width, pImg->height, pImg->imageData, &bmi,DIB_RGB_COLORS,SRCCOPY);
}
void FillBitmapInfo( BITMAPINFO* bmi, int width, int height, int bpp )
{
ASSERT(bmi && width > 0 && height > 0 && (bpp == 8 || bpp == 24 || bpp == 32) );
// BMP信息头
BITMAPINFOHEADER* bmih = &(bmi->bmiHeader);
memset( bmih, 0, sizeof(*bmih));
bmih->biSize = sizeof(BITMAPINFOHEADER);
bmih->biWidth = width;
bmih->biHeight = -abs(height);
bmih->biPlanes = 1;
bmih->biBitCount = bpp;
bmih->biCompression = BI_RGB;
// 调色板的填充
// 大于8的不需要调色板
if( bpp == 8 )
{
RGBQUAD* palette = bmi->bmiColors;
int i;
for( i = 0; i < 256; i++ )
{
palette[i].rgbBlue = palette[i].rgbGreen = palette[i].rgbRed = (BYTE)i;
palette[i].rgbReserved = 0;
}
}
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/hardVB/archive/2007/04/23/1575349.aspx
http://blog.csdn.net/hardVB/archive/2007/04/23/1575349.aspx
void OpenVCLoadPicture()
{
IplImage* pImg;
CString strPathName;
CFileDialog dlg(TRUE);
CDC* pDC = this->GetDC();
CRect rect;
this->GetClientRect(&rect);
if(dlg.DoModal()==IDOK)
{
strPathName = dlg.GetPathName();
// 加载一幅图片
pImg = cvLoadImage(strPathName);
BITMAPINFO bmi;
FillBitmapInfo(&bmi,pImg->width,pImg->height,(pImg->depth)*(pImg->nChannels));
// DC中绘制
::StretchDIBits(pDC->GetSafeHdc(), rect.left, rect.top, pImg->width, pImg->height, 0, 0,
pImg->width, pImg->height, pImg->imageData, &bmi,DIB_RGB_COLORS,SRCCOPY);
}
void FillBitmapInfo( BITMAPINFO* bmi, int width, int height, int bpp )
{
ASSERT(bmi && width > 0 && height > 0 && (bpp == 8 || bpp == 24 || bpp == 32) );
// BMP信息头
BITMAPINFOHEADER* bmih = &(bmi->bmiHeader);
memset( bmih, 0, sizeof(*bmih));
bmih->biSize = sizeof(BITMAPINFOHEADER);
bmih->biWidth = width;
bmih->biHeight = -abs(height);
bmih->biPlanes = 1;
bmih->biBitCount = bpp;
bmih->biCompression = BI_RGB;
// 调色板的填充
// 大于8的不需要调色板
if( bpp == 8 )
{
RGBQUAD* palette = bmi->bmiColors;
int i;
for( i = 0; i < 256; i++ )
{
palette[i].rgbBlue = palette[i].rgbGreen = palette[i].rgbRed = (BYTE)i;
palette[i].rgbReserved = 0;
}
}
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/hardVB/archive/2007/04/23/1575349.aspx
相关文章推荐
- OpenCV使用不同方式访问图像数据
- 2.9 opencv2 使用鼠标绘制矩形并截取和保存矩形区域图像
- vs2010搭载opencv2.4.10时Mat无法读入图像数据
- 在wxWidgets中使用OpenCV绘制摄像头图像
- 使用QT5绘制OpenCV3的Mat图像
- 使用python开启你的opencv之旅---图像的读入,存储
- opencv中图像数据使用方法
- 使用Linux的V4L2读取摄像头数据+Opencv图像处理
- 使用OpenCV实现内存中图像数据的RGB-->HSV转换
- 用Opencv读入图像,获取数据,操作后用另一个图像显示
- 使用opencv 绘制数据图
- opencv2 使用鼠标绘制矩形并截取和保存矩形区域图像
- opencv2 使用鼠标绘制矩形并截取和保存矩形区域图像
- 【caffe】使用自己的图像数据训练lenet并用opencv进行预测
- OpenCV学习笔记——使用OpenCV访问图像数据
- 在wxWidgets中使用OpenCV绘制摄像头图像
- OpenCV使用之读入存储图像
- Python下opencv使用笔记(二)(简单几何图像绘制)
- [good]opencv2 使用鼠标绘制矩形并截取和保存矩形区域图像
- opencv2 使用鼠标绘制矩形并截取和保存矩形区域图像