Click here to Skip to main content
13,353,706 members (56,310 online)
Rate this:
Please Sign up or sign in to vote.
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 29-Nov-12 2:44am
Updated 29-Nov-12 3:36am
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
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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;

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;
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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.


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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.180111.1 | Last Updated 6 Dec 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100