F项目进行到最终界面设计阶段了。在把320x240分辨率的摄像头图像放到640x480的视窗之后,解析度很低,决定添加让用户选择分辨率的界面。 
先看了DirectX自带的AmCap Sample,在里面找到这样一段代码: 
 IAMStreamConfig *pSC;
                IAMStreamConfig *pSC; 
 hr = gcap.pBuilder->FindInterface(&PIN_CATEGORY_CAPTURE,
                hr = gcap.pBuilder->FindInterface(&PIN_CATEGORY_CAPTURE, 
 &MEDIATYPE_Interleaved, gcap.pVCap,
                    &MEDIATYPE_Interleaved, gcap.pVCap, 
 IID_IAMStreamConfig, (void **)&pSC);
                    IID_IAMStreamConfig, (void **)&pSC); 
 
 
 if(hr != NOERROR)
                if(hr != NOERROR) 
 hr = gcap.pBuilder->FindInterface(&PIN_CATEGORY_CAPTURE,
                    hr = gcap.pBuilder->FindInterface(&PIN_CATEGORY_CAPTURE, 
 &MEDIATYPE_Video, gcap.pVCap,
                        &MEDIATYPE_Video, gcap.pVCap, 
 IID_IAMStreamConfig, (void **)&pSC);
                        IID_IAMStreamConfig, (void **)&pSC); 
 
 
 ISpecifyPropertyPages *pSpec;
                ISpecifyPropertyPages *pSpec; 
 CAUUID cauuid;
                CAUUID cauuid; 
 
 
 hr = pSC->QueryInterface(IID_ISpecifyPropertyPages,
                hr = pSC->QueryInterface(IID_ISpecifyPropertyPages, 
 (void **)&pSpec);
                    (void **)&pSpec); 
 
 
 if(hr == S_OK)
                if(hr == S_OK) 
 {
                { 
 hr = pSpec->GetPages(&cauuid);
                    hr = pSpec->GetPages(&cauuid); 
 hr = OleCreatePropertyFrame(ghwndApp, 30, 30, NULL, 1,
                    hr = OleCreatePropertyFrame(ghwndApp, 30, 30, NULL, 1, 
 (IUnknown **)&pSC, cauuid.cElems,
                        (IUnknown **)&pSC, cauuid.cElems, 
 (GUID *)cauuid.pElems, 0, 0, NULL);
                        (GUID *)cauuid.pElems, 0, 0, NULL); 
 
 
 // !!! What if changing output formats couldn't reconnect
                    // !!! What if changing output formats couldn't reconnect 
 // and the graph is broken?  Shouldn't be possible
                    // and the graph is broken?  Shouldn't be possible 
 
 
 
 if(gcap.pVSC)
                    if(gcap.pVSC) 
 {
                    { 
 AM_MEDIA_TYPE *pmt;
                        AM_MEDIA_TYPE *pmt; 
 // get format being used NOW
                        // get format being used NOW 
 hr = gcap.pVSC->GetFormat(&pmt);
                        hr = gcap.pVSC->GetFormat(&pmt); 
 
 
 // DV capture does not use a VIDEOINFOHEADER
                        // DV capture does not use a VIDEOINFOHEADER 
 if(hr == NOERROR)
                        if(hr == NOERROR) 
 {
                        { 
 if(pmt->formattype == FORMAT_VideoInfo)
                            if(pmt->formattype == FORMAT_VideoInfo) 
 {
                            { 
 // resize our window to the new capture size
                                // resize our window to the new capture size 
 ResizeWindow(HEADER(pmt->pbFormat)->biWidth,
                                ResizeWindow(HEADER(pmt->pbFormat)->biWidth, 
 abs(HEADER(pmt->pbFormat)->biHeight));
                                    abs(HEADER(pmt->pbFormat)->biHeight)); 
 }
                            } 
 DeleteMediaType(pmt);
                            DeleteMediaType(pmt); 
 }
                        } 
 }
                    } 
 
 
 CoTaskMemFree(cauuid.pElems);
                    CoTaskMemFree(cauuid.pElems); 
 pSpec->Release();
                    pSpec->Release(); 
 }
                } 
 
 
 pSC->Release();
                pSC->Release(); 
   先是用ICaptureGraphBuilder2::FindInterface将Capture Filter的属性读到IAMStreamConfig中,再通过QueryInterface将IAMStreamConfig与ISpecifyPropertyPages关联起来,然后利用OLE自带的OleCreatePropertyFrame来生成属性页面,供用户选取。
后面的代码是根据读到的信息调整UI,并作些结束处理。
以上实地一种方法,但是每次都要选择才能达到640x480的分辨率,感觉很不人性化,假如用户希望定义默认值为640x480而不是320x240,那就需要别的方法了。
在DirectX的文档中看到这样一篇文章:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnanchor/html/anch_directx.asp
先把Capture Filter的属性读到IAMStreamConfig:
 IAMStreamConfig *pConfig = NULL;
IAMStreamConfig *pConfig = NULL; 
 hr = pBuild->FindInterface(
hr = pBuild->FindInterface( 
 &PIN_CATEGORY_PREVIEW, // Preview pin.
    &PIN_CATEGORY_PREVIEW, // Preview pin. 
 0,    // Any media type.
    0,    // Any media type. 
 pCap, // Pointer to the capture filter.
    pCap, // Pointer to the capture filter. 
 IID_IAMStreamConfig, (void**)&pConfig);
    IID_IAMStreamConfig, (void**)&pConfig); 
 
 
   然后将属性中的每个AM_MEDIA_TYPE读出,处理。
 int iCount = 0, iSize = 0;
int iCount = 0, iSize = 0; 
 hr = pConfig->GetNumberOfCapabilities(&iCount, &iSize);
hr = pConfig->GetNumberOfCapabilities(&iCount, &iSize); 
 
 
 // Check the size to make sure we pass in the correct structure.
// Check the size to make sure we pass in the correct structure. 
 if (iSize == sizeof(VIDEO_STREAM_CONFIG_CAPS)
if (iSize == sizeof(VIDEO_STREAM_CONFIG_CAPS) 
 {
{ 
 // Use the video capabilities structure.
    // Use the video capabilities structure. 
 
 
 for (int iFormat = 0; iFormat < iCount; iFormat++)
    for (int iFormat = 0; iFormat < iCount; iFormat++) 
 {
    { 
 VIDEO_STREAM_CONFIG_CAPS scc;
        VIDEO_STREAM_CONFIG_CAPS scc; 
 AM_MEDIA_TYPE *pmtConfig;
        AM_MEDIA_TYPE *pmtConfig; 
 hr = pConfig->GetStreamCaps(iFormat, &pmtConfig, (BYTE*)&scc);
        hr = pConfig->GetStreamCaps(iFormat, &pmtConfig, (BYTE*)&scc); 
 if (SUCCEEDED(hr))
        if (SUCCEEDED(hr)) 
 {
        { 
 /* Examine the format, and possibly use it. */
            /* Examine the format, and possibly use it. */ 
 
 
 // Delete the media type when you are done.
            // Delete the media type when you are done. 
 DeleteMediaType(pmtConfig);
            DeleteMediaType(pmtConfig); 
 }
        } 
 }
} 
   在这里我要做的是,在众多支持的AM_MEDIA_TYPE中挑选一种合适的,作为默认选项。
 if ((pmtConfig->majortype == MEDIATYPE_Video) &&
                if ((pmtConfig->majortype == MEDIATYPE_Video) && 
 (pmtConfig->subtype == MEDIASUBTYPE_RGB24) &&
                    (pmtConfig->subtype == MEDIASUBTYPE_RGB24) && 
 (pmtConfig->formattype == FORMAT_VideoInfo) &&
                    (pmtConfig->formattype == FORMAT_VideoInfo) && 
 (pmtConfig->cbFormat >= sizeof (VIDEOINFOHEADER)) &&
                    (pmtConfig->cbFormat >= sizeof (VIDEOINFOHEADER)) && 
 (pmtConfig->pbFormat != NULL))
                    (pmtConfig->pbFormat != NULL)) 
 {
                { 
 VIDEOINFOHEADER *pVih = (VIDEOINFOHEADER*)pmtConfig->pbFormat;
                    VIDEOINFOHEADER *pVih = (VIDEOINFOHEADER*)pmtConfig->pbFormat; 
 // pVih contains the detailed format information.
                    // pVih contains the detailed format information. 
 LONG lWidth = pVih->bmiHeader.biWidth;
                    LONG lWidth = pVih->bmiHeader.biWidth; 
 LONG lHeight = pVih->bmiHeader.biHeight;
                    LONG lHeight = pVih->bmiHeader.biHeight; 
 if(lWidth == 640)
                    if(lWidth == 640) 
 pSC->SetFormat(pmtConfig);
                        pSC->SetFormat(pmtConfig); 
 }
                } 
   这样,初始模式就设在了640x480上,但是如果设备不支持640,就不会更改了。
第二种方法也成功了。
 
                    
                 
                 
                     
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号