資源簡介
編寫了圖像顯示的類,只需要把控件ID和文件名以及句柄傳送到函數,就可以顯示圖像,簡單示例,供大家學習,VS2010+Opencv2.4.9
代碼片段和文件信息
//?ImgToControls.cpp?:?implementation?file
//
#include?“stdafx.h“
#include?“PaintImgToScreenControls.h“
#include?“ImgToControls.h“
#include?“afxdialogex.h“
//?ImgToControls?dialog
IMPLEMENT_DYNAMIC(ImgToControls?CDialogEx)
ImgToControls::ImgToControls(CWnd*?pParent?/*=NULL*/)
:?CDialogEx(ImgToControls::IDD?pParent)
{
}
ImgToControls::~ImgToControls()
{
}
void?ImgToControls::DoDataExchange(CDataExchange*?pDX)
{
CDialogEx::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(ImgToControls?CDialogEx)
END_MESSAGE_MAP()
//?ImgToControls?message?handlers
void??ImgToControls::drawpicinit(IplImage*?img?unsigned?int?idCWnd*?showWnd)??
{??
//位圖信息初始化??
bmibuf?=?new?BYTE[sizeof(BITMAPINFO)+256?*?sizeof(RGBQUAD)];??
memset(bmibuf?0?sizeof(bmibuf));??
pbmi?=?(BITMAPINFO*)bmibuf;??
pbmi->bmiHeader.biSize?=?sizeof(BITMAPINFOHEADER);??
pbmi->bmiHeader.biWidth?=?img->width;??
pbmi->bmiHeader.biHeight?=?img->height;??
pbmi->bmiHeader.biPlanes?=?1;??
pbmi->bmiHeader.biBitCount?=?24;??
pbmi->bmiHeader.biCompression?=?BI_RGB;???
mShowWnd?=?showWnd;??
pDC?=?mShowWnd->GetDlgItem(id)->GetDC();??
pic?=?(CStatic*)mShowWnd->GetDlgItem(id);??
pic->GetClientRect(&rect);??
g_hMemDC?=?CreateCompatibleDC(pDC->m_hDC);//創建兼容設備環境的內存DC??
g_hBmp?=?CreateDIBSection(g_hMemDC?pbmi?DIB_RGB_COLORS?(void**)&g_pBits?0?0);//創建應用程序可以直接寫入的、與設備無關的位圖??
}??
void?ImgToControls::drawpic(IplImage*?img)//CMFCOpenCVShowDlg?為對話框類名??
{??
//修改圖像內容:g_pBits??
//這里這么做一則為BMP圖像的四字節對齊機制,二則是因為BMP圖像是從圖像的左下角開始算起的,如果直接拷貝會導致圖像上下顛倒??
int?l_width?=?WIDTHBYTES(img->width*?pbmi->bmiHeader.biBitCount);??
for?(int?row?=?0;?row?height;?row++)??
memcpy(&g_pBits[row*l_width]?&img->imageData[(img->height?-?row?-?1)*l_width]?l_width);??
Selectobject(g_hMemDC?g_hBmp);//將位圖對象選入g_hMemDC內存DC中??
//拉伸繪圖??
SetStretchBltMode(pDC->m_hDC?HALFTONE);??
StretchBlt(pDC->m_hDC?0?0?rect.Width()?rect.Height()?g_hMemDC?0?0?img->width?img->height?SRCCOPY);??
}??
void?ImgToControls::drawrelease()??
{??
//釋放內存資源??????
delete[]bmibuf;??
DeleteDC(g_hMemDC);??
Deleteobject(pic);??
Deleteobject(g_hBmp);??
mShowWnd->ReleaseDC(pDC);??
}??
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????3418??2017-11-27?15:09??PaintImgToScreenControls\Debug\cl.command.1.tlog
?????文件?????100728??2017-11-27?15:09??PaintImgToScreenControls\Debug\CL.read.1.tlog
?????文件???????2660??2017-11-27?15:09??PaintImgToScreenControls\Debug\CL.write.1.tlog
?????文件?????129658??2017-11-27?15:09??PaintImgToScreenControls\Debug\ImgToControls.obj
?????文件??????????2??2017-11-27?15:09??PaintImgToScreenControls\Debug\li
?????文件??????????2??2017-11-27?15:09??PaintImgToScreenControls\Debug\li
?????文件???????3310??2017-11-27?15:09??PaintImgToScreenControls\Debug\li
?????文件???????9042??2017-11-27?15:09??PaintImgToScreenControls\Debug\li
?????文件???????1754??2017-11-27?15:09??PaintImgToScreenControls\Debug\li
?????文件????????884??2017-11-27?15:09??PaintImgToScreenControls\Debug\mt.command.1.tlog
?????文件????????598??2017-11-27?15:09??PaintImgToScreenControls\Debug\mt.read.1.tlog
?????文件????????634??2017-11-27?15:09??PaintImgToScreenControls\Debug\mt.write.1.tlog
?????文件???????2599??2017-11-27?15:09??PaintImgToScreenControls\Debug\PaintImgToScreenControls.Build.CppClean.log
?????文件????????667??2017-11-27?15:09??PaintImgToScreenControls\Debug\PaintImgToScreenControls.exe.em
?????文件????????732??2017-11-27?15:09??PaintImgToScreenControls\Debug\PaintImgToScreenControls.exe.em
?????文件????????381??2017-11-27?15:09??PaintImgToScreenControls\Debug\PaintImgToScreenControls.exe.intermediate.manifest
?????文件?????????60??2017-11-27?15:09??PaintImgToScreenControls\Debug\PaintImgToScreenControls.lastbuildstate
?????文件???????5347??2017-11-27?15:09??PaintImgToScreenControls\Debug\PaintImgToScreenControls.log
?????文件??????30321??2017-11-27?15:09??PaintImgToScreenControls\Debug\PaintImgToScreenControls.obj
?????文件???33816576??2017-11-27?15:09??PaintImgToScreenControls\Debug\PaintImgToScreenControls.pch
?????文件??????69992??2017-11-27?15:09??PaintImgToScreenControls\Debug\PaintImgToScreenControls.res
?????文件??????????0??2017-11-27?15:09??PaintImgToScreenControls\Debug\PaintImgToScreenControls.write.1.tlog
?????文件?????146879??2017-11-27?15:09??PaintImgToScreenControls\Debug\PaintImgToScreenControlsDlg.obj
?????文件????????238??2017-11-27?15:09??PaintImgToScreenControls\Debug\PaintImgToScreenControls_manifest.rc
?????文件???????1528??2017-11-27?15:09??PaintImgToScreenControls\Debug\rc.command.1.tlog
?????文件???????3910??2017-11-27?15:09??PaintImgToScreenControls\Debug\rc.read.1.tlog
?????文件????????798??2017-11-27?15:09??PaintImgToScreenControls\Debug\rc.write.1.tlog
?????文件?????641909??2017-11-27?15:09??PaintImgToScreenControls\Debug\stdafx.obj
?????文件????2460672??2017-11-27?15:09??PaintImgToScreenControls\Debug\vc100.idb
?????文件????4386816??2017-11-27?15:09??PaintImgToScreenControls\Debug\vc100.pdb
............此處省略42個文件信息
評論
共有 條評論