当前位置: 代码迷 >> 多媒体/流媒体开发 >> 小弟我的摄像头在640*480分辨率的时候只显示左上角。分辨率越大,显示的越小
  详细解决方案

小弟我的摄像头在640*480分辨率的时候只显示左上角。分辨率越大,显示的越小

热度:2221   发布时间:2013-02-26 00:00:00.0
我的摄像头在640*480分辨率的时候只显示左下角。分辨率越大,显示的越小

int count = 0;
int s = 0;

hr = pConfig->GetNumberOfCapabilities(&count, &s);
if (FAILED(hr))
{
pConfig->Release();
return false;
}

if (s != sizeof(VIDEO_STREAM_CONFIG_CAPS))
{
pConfig->Release();
return false;
}

for (int i = 0; i < count; i++)
{
        VIDEO_STREAM_CONFIG_CAPS caps;
        AM_MEDIA_TYPE *pMediaType;

        hr = pConfig->GetStreamCaps(i, &pMediaType, (BYTE*)&caps);
        if (SUCCEEDED(hr))
        {
if ((pMediaType->majortype == MEDIATYPE_Video) &&
(pMediaType->subtype == m_selectedGuid) &&
(pMediaType->formattype == FORMAT_VideoInfo) &&
(pMediaType->cbFormat >= sizeof (VIDEOINFOHEADER)) &&
(pMediaType->pbFormat != 0))
{
VIDEOINFOHEADER *pVih = (VIDEOINFOHEADER*)pMediaType->pbFormat;
//测试
//CLogFile gLog("");
//CStringA strTemp;
//strTemp.Format("1-setFormat,%d, %d - %d, %d", pVih->bmiHeader.biWidth, pVih->bmiHeader.biHeight, w, h);
//gLog.Log(strTemp);
//end
pVih->bmiHeader.biWidth = w;
pVih->bmiHeader.biHeight = h;
//pVih->bmiHeader.biSizeImage = w   *   h   *   pVih-> bmiHeader.biBitCount   /   8;
pVih->bmiHeader.biSizeImage = DIBSIZE(pVih->bmiHeader);
pVih->AvgTimePerFrame = (REFERENCE_TIME)(10000000.0/rate);
////测试

// CRect rc;
// CWnd *pWnd = CWnd::FromHandle (m_hVideoWnd);//GetDlgItem (IDC_STC_PLAYAREA);
// pWnd->GetClientRect (&rc);
// //pWnd->ClientToScreen (&rc);
// //ScreenToClient (&rc);
// hr = m_pVW_v->SetWindowPosition(rc.left, rc.top, rc.Width(), rc.Height());
////end
hr = pConfig->SetFormat(pMediaType);
if (SUCCEEDED(hr))
{
//测试
//CLogFile gLog("");
//CStringA strTemp;
//strTemp.Format("SetFormat,OK!");
//gLog.Log(strTemp);

//end
CoTaskMemFree(pMediaType->pbFormat);
pConfig->Release();
return true;
}
}

if (pMediaType->pbFormat != 0)
CoTaskMemFree(pMediaType->pbFormat);
}
}

pConfig->Release();
代码如上。反正好多代码,我看了好久,找不到出错的原因。真的很纠结,求解决
------解决方案--------------------------------------------------------
加我qq332574182吧,平常加班很晚才回家,公司里面不能上网。等周六的时候qq可能才上。估计是你调用例子的问题,你要是格式或者分辨率设置不对,显示的肯定是条纹数据或者显示不出来。你可以先用graphedit链接试试嘛
------解决方案--------------------------------------------------------
SetWindowPosition时,视频源矩型没指对,你要指定是视频的大小,而不是窗口大小,第二个区域才是窗口大小。

如果你的视频源指定为窗口大小,就会出现你说的情况,部分显示。
  相关解决方案