I have some code that uses an IID_IAMStreamConfig interface to set the camera image size. I didn't use it to set the image format, but I added the code that I think will do the job. It is untested however.
// 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;
}
You should place the code after the following block in amcap:
if(hr != NOERROR)
hr = gcap.pBuilder->FindInterface(&PIN_CATEGORY_CAPTURE,
&MEDIATYPE_Video, gcap.pVCap,
IID_IAMStreamConfig, (void **)&pSC);
Again, this is untested code, but you can try it and I hope it helps.