Directshow 擷取圖片問題題--請大大幫我解答 |
尚未結案
|
ken911629
一般會員 ![]() ![]() 發表:7 回覆:4 積分:2 註冊:2005-11-10 發送簡訊給我 |
以下是小弟的程式,可以看到預覽的的畫面
可是儲存的檔案temp.bmp無法開啟...用小畫家開啟會顯示"無法辨識的格式"
探討的原因有可能是圖片並沒有寫入檔案當中..只有產生了檔案(檔案大小150K) hr = CoCreateInstance (CLSID_FilterGraph, NULL, CLSCTX_INPROC,
IID_IGraphBuilder, (void **) &m_pGraph);
if (FAILED(hr))
return hr;
// Create the capture graph builder
hr = CoCreateInstance (CLSID_CaptureGraphBuilder2 , NULL, CLSCTX_INPROC,
IID_ICaptureGraphBuilder2, (void **) &m_pCapture);
if (FAILED(hr))
return hr;
// pGrabber.CoCreateInstance( CLSID_SampleGrabber );
// Create the Sample Grabber.
IBaseFilter *pGrabberF = NULL;
hr = CoCreateInstance(CLSID_SampleGrabber, NULL, CLSCTX_INPROC_SERVER,
IID_IBaseFilter, (void**)&pGrabberF);
if (FAILED(hr))
return hr;
// Obtain interfaces for media control and Video Window
hr = m_pGraph->QueryInterface(IID_IMediaControl,(LPVOID *) &m_pMC);
if (FAILED(hr))
return hr;
hr = m_pGraph->QueryInterface(IID_IVideoWindow, (LPVOID *) &m_pVW);
hr = m_pVW->put_AutoShow(OAFALSE);
hr = m_pGraph->QueryInterface(IID_IMediaEvent, (LPVOID *) &m_pME);
if (FAILED(hr))
return hr;
ISampleGrabber *pGrabber;
pGrabberF->QueryInterface(IID_ISampleGrabber, (void**)&pGrabber);
hr = m_pME->SetNotifyWindow((OAHWND)(m_hWnd), WM_GRAPHNOTIFY, 0);
hr = m_pCapture->SetFiltergraph(m_pGraph);
IMoniker *pMoniker = NULL;
ICreateDevEnum *pDevEnum = 0;
IEnumMoniker *pClassEnum = NULL;
ULONG cFetched;
hr = CoCreateInstance (CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC,IID_ICreateDevEnum, (void **) &pDevEnum);
hr = pDevEnum->CreateClassEnumerator (CLSID_VideoInputDeviceCategory, &pClassEnum, 0);
if (hr==S_OK) //發現TV Card
{
pClassEnum->Next (1, &pMoniker, &cFetched);
hr = pMoniker->BindToObject(0,0,IID_IBaseFilter, (void**)&pVcap);
if (FAILED(hr))
return hr;
pClassEnum = NULL;
hr = m_pGraph->AddFilter(pVcap, L"Video Capture");
hr = m_pGraph->AddFilter(pGrabberF, L"Sample Grabber");
hr = m_pCapture->RenderStream (&PIN_CATEGORY_PREVIEW, &MEDIATYPE_Video,pVcap, NULL, NULL);
hr = m_pCapture->FindInterface(&PIN_CATEGORY_CAPTURE,&MEDIATYPE_Video, pVcap,IID_IAMTVTuner, (void **)&pIAMTVTuner)
hr = m_pCapture->FindInterface(&LOOK_UPSTREAM_ONLY, NULL, pVcap,IID_IAMCrossbar, (void**)&pIAMCrossbar);
RECT rc;
::GetClientRect(m_hWnd, &rc);
設定可視
m_pVW->put_Owner((OAHWND) m_hWnd);
m_pVW->put_WindowStyle(WS_CHILD | WS_CLIPCHILDREN);
m_pVW->SetWindowPosition(0, 0, rc.right , rc.bottom );
hr = m_pVW->put_Visible(OATRUE);
pIAMCrossbar->Route(1,1);
IsCreate=1;
//m_pMC->Run();
ShowMessage("OPEN_OCX_TV CARD ok!");
//Sleep(500);
//取得當前所連接媒體的類型
//
AM_MEDIA_TYPE mt;
ZeroMemory(&mt, sizeof(AM_MEDIA_TYPE));
mt.majortype = MEDIATYPE_Video;
mt.subtype = MEDIASUBTYPE_RGB24;
hr = pGrabber->SetMediaType(&mt);
//CComPtr
|
taishyang
站務副站長 ![]() ![]() ![]() ![]() ![]() ![]() 發表:377 回覆:5490 積分:4563 註冊:2002-10-08 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |