我有一些代码使用 IID_IAMStreamConfig 接口来设置相机图像大小。我没有使用它来设置图像格式,但我添加了我认为可以完成这项工作的代码。然而,它未经测试。
// get the number of formats and make sure the strutucre size matches
int count;
int size;
VIDEO_STREAM_CONFIG_CAPS caps;
pSC->GetNumberOfCapabilities(&count, &size);
if( sizeof(caps) != size )
{
// Error
}
AM_MEDIA_TYPE* mt_p = NULL;
hr = pSC->GetStreamCaps(0, &mt_p, (BYTE*)&caps);
if (hr != S_OK)
{
// Error
}
if ((mt_p->majortype != MEDIATYPE_Video) || (mt_p->formattype != FORMAT_VideoInfo))
{
// Error
}
VIDEOINFOHEADER* video_info_header_p = (VIDEOINFOHEADER *)mt_p->pbFormat;
video_info_header_p->bmiHeader.biWidth = 1600;
video_info_header_p->bmiHeader.biHeight = 1200;
// Code to change video format
// I think 16 is the right value for biBitCount, but I am not sure!!!!
video_info_header_p->bmiHeader.biCompression = MAKEFOURCC('Y','U','Y','2');
video_info_header_p->bmiHeader.biBitCount = 16;
hr = pSC->SetFormat(mt_p);
if (hr != S_OK)
{
// Error
}
if (mt_p->cbFormat != 0)
{
CoTaskMemFree((PVOID)mt_p->pbFormat);
mt_p->cbFormat = 0;
mt_p->pbFormat = NULL;
}
if (mt_p->pUnk != NULL)
{
// Unecessary because pUnk should not be used, but safest.
mt_p->pUnk->Release();
mt_p->pUnk = NULL;
}
您应该将代码放在 amcap 中的以下块之后:
if(hr != NOERROR)
hr = gcap.pBuilder->FindInterface(&PIN_CATEGORY_CAPTURE,
&MEDIATYPE_Video, gcap.pVCap,
IID_IAMStreamConfig, (void **)&pSC);
同样,这是未经测试的代码,但您可以尝试一下,希望对您有所帮助。