利用网上的代码做了一个视频采集的小程序,现在需要实现如下功能已有如下函数:
/*******************************************************************************
   Function   : EnablePreviewVideo
   Arguments  : Parent (input) - Parent window that will display video.
                x (input) - X Location in parent where video will be shown.
                y (input) - Y location in parent where video will be shown.
                Width (input) - Width of preview window.
                Height (input) - Height of preview window.
                PreviewRate (input) - Rate of preview in FPS.
   Return     : TRUE Success, FALSE Failed.
   Description: Enables preview video mode.
*******************************************************************************/
BOOL CVFWImageProcessor::EnablePreviewVideo(HWND Parent, INT x, INT y, INT Width, INT Height, INT PreviewRate)
{
   // Reset any error conditions.
   GetPreviousError(NULL,NULL,TRUE);   SetParent(m_hWndVideo,Parent);
   SetWindowLong(m_hWndVideo,GWL_STYLE,WS_CHILD);   SetWindowPos(m_hWndVideo,NULL,x,y,
                Width,
                Height,
                SWP_NOZORDER);
   ShowWindow(m_hWndVideo,SW_SHOW);
   capPreviewRate(m_hWndVideo, PreviewRate);   return capPreview(m_hWndVideo,TRUE);
}现在已经通过获取预览窗口CRect rectVideo的大小,但是视频显示的还是与视频格式设置大小一致,只能在窗口内显示视频左上角的一部分,没有实现视频的缩放,所以显示不全。我现在就想缩放视频预览显示到设定区域,但实际的视频大小不要改变,因为抓图还是要实际大小的。哪位大侠熟悉视频窗口大小控制的帮忙啊,老大已经催着完工了,着急啊!

解决方案 »

  1.   

    将采集出来的数据,送给自己的显示程序。要缩放的话最好用Overlay.
      

  2.   

    我仅仅想缩放一下动态视频窗口,采集后的数据如何再显示为动态视频?还有Overlay有没有例子啊
      

  3.   

    DirectX 9.0中找
    IVideoWindow的
    SetWindowPosition 方法
      

  4.   

    HRESULT SetWindowPosition(
      long Left,
      long Top,
      long Width,
      long Height
    );ParametersLeft[in] Specifies the x-coordinate, in pixels. Top[in] Specifies the y-coordinate, in pixels. Width[in] Specifies the width, in pixels. Height[in] Specifies the height, in pixels. 
      

  5.   

    如果不是摄像头支持的大小(176*144,320*240等),一般都是通过自已转换成小的再显示。
    简单的转换可以用StretchBlt,不过很占CPU。
      

  6.   

    自动缩放视频到视频窗口大小:
    在你的capPreviewRate(...)之后加上capPreviewScale(hwnd,TRUE)试试附MSDN:
    BOOL capPreviewScale( hwnd, f );Parameters
    hwnd 
    Handle of a capture window. 

    Preview scaling flag. Specify TRUE for this parameter to stretch preview frames to the size of the capture window or FALSE to display them at their natural size. 
    Return Values
    Returns TRUE if successful or FALSE otherwise.Res
    Scaling preview images controls the immediate presentation of captured frames within the capture window. It has no effect on the size of the frames saved to file.Scaling has no effect when using overlay to display video in the frame buffer.
    另:
    抓图时候设置大小:
    HWND m_capwnd=capCreateCaptureWindow(.......);
    BITMAPINFO m_bmpinfo;
    capGetVideoFormat(m_capwnd,&m_bmpinfo,sizeof(m_bmpinfo));m_bmpinfo.bmiHeader.biWidth和m_bmpinfo.bmiHeader.biHeight就是你想要的视频宽度和高度设置大小:
    m_bmpinfo.bmiHeader.biWidth=176;//320
    m_bmpinfo.bmiHeader.biHeight=144;//240
    BOOL ret=capSetVideoFormat(m_capwnd,&m_bmpinfo,sizeof(m_bmpinfo));
      

  7.   

    终于解决了,capPreviewScale就加这么个伸缩函数就OK了,费了我那么大劲还是不熟悉的原因啊。谢谢诸位帮忙,可能雅克的方法也行,不过我理解不了,只要找简单的来实现了,嘿嘿