在视频上绘制基本形状 [英] draws basic shapes over video

查看:106
本文介绍了在视频上绘制基本形状的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要有关C#应用程序的帮助,该应用程序即使在播放时也会在视频上绘制基本形状。我正在使用AXWindowsMediaPlayer控件来播放视频,并且还使用自定义面板在播放器控件上绘制形状。自定义面板是透明的。视频播放时可以顺畅绘制。但是当它出现时,每件事都出错了。视频上的绘图被删除。我怎么能克服这个问题?请帮助。

need help on an C# application that draws basic shapes over video even when it plays. I am using AXWindowsMediaPlayer control for playing video and also put a custom Panel to draw shapes over player control. Custom panel is transparent. can draw smoothly while video is not playing. But when it plays every thing goes wrong. the drawing over the video get erased. How i can overcome the issue ? Please help.

推荐答案

我发现了如何做到这一点。

这里是使用Canvas的WPF中的一种方式

i have found how to do this.
here is one way in WPF using 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();
        }
    }
</bool>



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


then create mouse events for Canvas and draw with it

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);
}


您无法在播放时使用的活动电影窗口上手动绘制。如果您需要在预览时执行此操作,或者在任何情况下使用DirectShow过滤器,则可以更好地组织实现自定义视频呈现内容。公平简单但不恰当的是通过ISampleGrabber进行回调并获取可以与您的东西一起绘制的视频图像。



Maxim。
You can''t draw manually on active movie window which is used in playback. This is better organized with implementing custom video presenting stuff if you need to do that while preview, or inside DirectShow filter for any cases. Fair easy way but not proper is to make callback via ISampleGrabber and pick up the video images which you can draw along with your stuff.

Maxim.


这篇关于在视频上绘制基本形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆