1

即使在播放视频时也需要在视频上绘制基本形状的应用程序的帮助。我正在使用 AXWindowsMediaPlayer 控件来播放视频,并且还放置了一个自定义面板来在播放器控件上绘制形状。自定义面板是透明的。视频不播放时可以流畅绘制。但是当它播放时,一切都会出错。视频上的绘图被删除。我怎样才能克服这个问题?请帮忙。

4

1 回答 1

3

我已经找到了如何做到这一点。这是在 WPF 中使用 Canvas 的一种方式

private void buttonPlayVideo_Click(object sender, RoutedEventArgs e)
{
    Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
    dlg.Filter = "All Files|*.*";
    Nullable<bool> result = dlg.ShowDialog();
    if (result == true) {
        MediaPlayer mp = new MediaPlayer();
        mp.Open(new Uri(filename));
        VideoDrawing vd = new VideoDrawing();
        vd.Player = mp;
        vd.Rect = new Rect(0, 0, 960, 540);
        DrawingBrush db = new DrawingBrush(vd);
        canvas.Background = db;
        mp.Play();
    }
}

然后为 Canvas 创建鼠标事件并用它绘制

    Point startPoint, endPoint;
    private void canvas_MouseDown(object sender, MouseButtonEventArgs e)
    {
        startPoint = e.GetPosition(canvas);
    }
    private void canvas_MouseUp(object sender, MouseButtonEventArgs e)
    {
        endPoint = e.GetPosition(canvas);

        Line myLine = new Line();
        myLine.Stroke = System.Windows.Media.Brushes.LightSteelBlue;
        myLine.X1 = startPoint.X;
        myLine.Y1 = startPoint.Y;
        myLine.X2 = endPoint.X;
        myLine.Y2 = endPoint.Y;
        myLine.HorizontalAlignment = HorizontalAlignment.Left;
        myLine.VerticalAlignment = VerticalAlignment.Center;
        myLine.StrokeThickness = 2;
        canvas.Children.Add(myLine);
    }
于 2012-12-06T04:26:14.547 回答