【问题标题】:C# DirectShow .Net Centre video with backgroundC# DirectShow .Net 中心视频带背景
【发布时间】:2012-02-12 18:47:24
【问题描述】:

我正在使用 DirectShow .NET 以 C# 形式在控件中显示视频。当表单和控件变大/变小时,我需要让视频填充控件(MainForm_ResizeMove 的 if 分支处理此问题)。如果设置了属性,我还需要保持源视频大小。 MainForm_ResizeMove 的 else 部分中的代码处理这个问题。我遇到的问题是,当其他部分将我的视频定位在以控件为中心的正确位置时,背景是灰色的。由于我已将视频位置设置为视频的大小,因此不应用边框颜色(因为在这种情况下没有边框)。有人可以建议最好的解决方案是什么吗?

private IVMRWindowlessControl9 windowlessCtrl = null;

...
private void MainForm_Paint(object sender, PaintEventArgs e)
    {           
        if (windowlessCtrl != null)
        {
            IntPtr hdc = e.Graphics.GetHdc();
            int hr = windowlessCtrl.SetBorderColor(0x00FFFFFF);
            hr = windowlessCtrl.RepaintVideo(this.Handle, hdc);
            e.Graphics.ReleaseHdc(hdc);
        }
    }

    private void MainForm_ResizeMove(object sender, EventArgs e)
    {
        if (windowlessCtrl != null)
        {
            if (fillScreen || (this.ClientRectangle.Width < streamFrameWidth) || (this.ClientRectangle.Height < streamFrameHeight))
            {
                int hr = windowlessCtrl.SetVideoPosition(null, DsRect.FromRectangle(this.ClientRectangle));
            }
            else
            {
                Rectangle rect = new Rectangle((this.ClientRectangle.Width / 2) - (streamFrameWidth / 2), 
                                               (this.ClientRectangle.Height/ 2) - (streamFrameHeight / 2), 
                                                streamFrameWidth, streamFrameHeight);
                int hr = windowlessCtrl.SetVideoPosition(null, rect);  
            } 
        }
    }

【问题讨论】:

    标签: c# directshow directshow.net


    【解决方案1】:

    其实很简单,把控件的背景色设置为黑色!!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-25
      • 1970-01-01
      • 2022-01-22
      • 2015-01-10
      • 2021-12-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多