Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Updated 29-Nov-12 2:36am
v2
Comments
Akeeq 3-Dec-12 0:42am    
how to add a glass layer over video player to draw on it ?
anything possible if do stuff in wpf. tried but same problem

i have found how to do this.
here is one way in WPF using Canvas
C#
    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>

then create mouse events for Canvas and draw with it
C#
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);
}
 
Share this answer
 
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900