접기
#if !defined(AFX_UUIDS_H__3F5BAE08_581B_4008_ABB4_0A4D2D3456C6__INCLUDED_)
#define AFX_UUIDS_H__3F5BAE08_581B_4008_ABB4_0A4D2D3456C6__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// SampleGrabber {C1F400A0-3F08-11D3-9F0B-006008039E37}
DEFINE_GUID(CLSID_L544_SampleGrabber,
0xc1f400a0, 0x3f08, 0x11d3, 0x9f, 0xb, 0x0, 0x60, 0x8, 0x3, 0x9e, 0x37);
#endif // !defined(AFX_UUIDS_H__3F5BAE08_581B_4008_ABB4_0A4D2D3456C6__INCLUDED_)
class CSampleGrabStillApp
{
...
private:
// DirectShow interfaces
// {
void CaptureScreen();
// }
IGraphBuilder * m_pGB ;
// {
IBaseFilter * m_pSG ;
// {
} ;
...
#include "myuuids.h"
// {
#include <qedit.h>
// }
...
CSampleGrabStillApp::CSampleGrabStillApp() : m_hInstance(NULL),
...
m_pGB(NULL), m_pSG(NULL)
{
...
}
HRESULT CSampleGrabStillApp::OnFileOpen()
{
...
// 필터그래프매니저 생성
// Get the interface for DirectShow's GraphBuilder
JIF(CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&m_pGB)) ;
// Add a Filter ... Put a filter in the graph
LIF(CoCreateInstance(CLSID_L544_SampleGrabber, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void **)&m_pSG )) ;
LIF(m_pGB->AddFilter(m_pSG, L"SampleGrabber"));
// {
AM_MEDIA_TYPE mt; ZeroMemory(&mt, sizeof(mt)); mt.majortype = MEDIATYPE_Video; // mt.majortype = MEDIATYPE_Audio; mt.subtype = MEDIASUBTYPE_RGB24; // mt.subtype = MEDIASUBTYPE_PCM; CComQIPtr<ISampleGrabber> pSampleGrabber(m_pSG); if (pSampleGrabber != NULL) { LIF(pSampleGrabber->SetMediaType(&mt)); LIF(pSampleGrabber->SetBufferSamples(TRUE)); }
// }
// Render File ...
// Have the graph construct its the appropriate graph automatically
JIF(m_pGB->RenderFile(wFileName, NULL)) ;
...
}
HRESULT CSampleGrabStillApp::OnFileClose()
{
...
// Release Filter Graph Manager
SAFE_RELEASE(m_pGB) ;
// {
SAFE_RELEASE(m_pSG) ;
// }
// 기본 윈도우 타이틀로 변경
SetWindowText(m_hWnd, m_szAppTitle) ;
return S_OK ;
}
...
void CSampleGrabStillApp::CaptureScreen() { if (m_pSG == NULL) return; HRESULT hr; CComQIPtr<ISampleGrabber> pSampleGrabber(m_pSG); if (pSampleGrabber == NULL) return; long lBufferSize; hr = pSampleGrabber->GetCurrentBuffer(&lBufferSize, NULL); if (FAILED(hr)) return; BYTE* pBuffer = new BYTE[lBufferSize]; if (!pBuffer) return; hr = pSampleGrabber->GetCurrentBuffer(&lBufferSize, (long *)pBuffer); if (SUCCEEDED(hr)) { AM_MEDIA_TYPE mt; pSampleGrabber->GetConnectedMediaType(&mt); VIDEOINFOHEADER *pviHeader = (VIDEOINFOHEADER *)mt.pbFormat; ::SaveImage(pviHeader->bmiHeader, pBuffer); } delete pBuffer; }
...
// Initialize CLSIDs
#include <initguid.h>
#include "myuuids.h"
...
LRESULT CSampleGrabStillApp::KeyProc(WPARAM wParam, LPARAM lParam)
{
switch (wParam)
{
...
// TODO: Place code here.
case 'F':
ToggleFullScreen();
break ;
// {
case VK_SNAPSHOT: CaptureScreen(); break ;
// }
}
return (DefWindowProc(m_hWnd, WM_KEYUP, wParam, lParam)) ;
}
접기