?? video demoview.cpp
字號:
// Video DemoView.cpp : implementation of the CVideoDemoView class
//
#include "stdafx.h"
#include "Video Demo.h"
#include "Video DemoDoc.h"
#include "Video DemoView.h"
#include "colortrans.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CVideoDemoView
IMPLEMENT_DYNCREATE(CVideoDemoView, CView)
BEGIN_MESSAGE_MAP(CVideoDemoView, CView)
//{{AFX_MSG_MAP(CVideoDemoView)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CVideoDemoView construction/destruction
CVideoDemoView::CVideoDemoView()
{
// TODO: add construction code here
this->data = NULL;
this->outputAvailable = false;
}
CVideoDemoView::~CVideoDemoView()
{
if(this->data != NULL)
delete[] data; // 釋放輸出緩沖
}
BOOL CVideoDemoView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CVideoDemoView drawing
/////////////////////////////////////////////////////////////////////////////
// CVideoDemoView printing
BOOL CVideoDemoView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CVideoDemoView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CVideoDemoView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CVideoDemoView diagnostics
#ifdef _DEBUG
void CVideoDemoView::AssertValid() const
{
CView::AssertValid();
}
void CVideoDemoView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CVideoDemoDoc* CVideoDemoView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CVideoDemoDoc)));
return (CVideoDemoDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CVideoDemoView message handlers
/************************************************************************/
/* 繪圖函數 */
/************************************************************************/
void CVideoDemoView::OnDraw(CDC* pDC)
{
if(outputAvailable) // 允許輸出圖像數據
{
pDC->SetStretchBltMode(STRETCH_DELETESCANS);
StretchDIBits(pDC->m_hDC,0,0,imgWidth,imgHeight,
0,0,imgWidth,imgHeight,
data, &bitmapInfo, DIB_RGB_COLORS,SRCCOPY);
}
}
/************************************************************************/
/* OnActiveView */
/* 當視圖切換時改變當前數據 */
/************************************************************************/
void CVideoDemoView::OnActivateView(BOOL bActivate,CView* pActivateView,CView* pDeactiveView)
{
if(bActivate == TRUE)
{
CVideoDemoDoc *doc = (CVideoDemoDoc*)GetDocument();
theApp.lastImageData = theApp.curImageData; // 設置上一次的數據位置
theApp.curImageData = doc->id; // 設置當前的doc
if(doc->id != NULL)
TRACE("Change View Index : %d\n",doc->id->index);
else
TRACE("Change View Index NULL ID\n");
}
}
/************************************************************************/
/* 允許輸出數據 */
/************************************************************************/
void CVideoDemoView::RefreshData()
{
// 自動獲取圖像數據源
CVideoDemoDoc* pDoc = GetDocument();
//ASSERT_VALID(pDoc);
// 顯示圖像
ImageData *id = pDoc->id; // 圖像數據
if(data != NULL)
delete[] data;
data = new unsigned char[id->imgWidth * id->imgHeight * 3];
ColorTrans ct;
switch(id->format)
{
case IMAGE_FORMAT_GRAY8:
// 8位灰度圖像
ct.gray2RGB2(id->data,data,id->imgWidth,id->imgHeight);
this->imgWidth = id->imgWidth;
this->imgHeight = id->imgHeight;
memset(&bitmapInfo,0,sizeof(BITMAPINFO));
bitmapInfo.bmiHeader.biHeight = (LONG)imgHeight;
bitmapInfo.bmiHeader.biWidth = (LONG)imgWidth;
bitmapInfo.bmiHeader.biSizeImage = (LONG)imgWidth * (LONG)imgHeight * 3;
bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bitmapInfo.bmiHeader.biBitCount = 24;
bitmapInfo.bmiHeader.biCompression = 0;
bitmapInfo.bmiHeader.biPlanes = 1;
outputAvailable = true; //輸出允許
break;
case IMAGE_FORMAT_RGB24:
memcpy(this->data,id->data,id->imgWidth * id->imgHeight * sizeof(unsigned char) * 3);
this->imgWidth = id->imgWidth;
this->imgHeight = id->imgHeight;
bitmapInfo.bmiHeader.biHeight = (LONG)imgHeight;
bitmapInfo.bmiHeader.biWidth = (LONG)imgWidth;
bitmapInfo.bmiHeader.biSizeImage = (LONG)imgWidth * (LONG)imgHeight * 3;
bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bitmapInfo.bmiHeader.biBitCount = 24;
bitmapInfo.bmiHeader.biCompression = 0;
bitmapInfo.bmiHeader.biPlanes = 1;
this->outputAvailable = true;
break;
default:
this->outputAvailable = false; // 輸出禁止
}
this->Invalidate(false);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -