Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drawing on Video within C#

I am making an application that will allow users to apply certain tools to analyse videos & images. I need help with how i actaully draw/write on the video loaded into windows media player within my form and being able to save it on. It needs to be able to lert the user draw freehand and shapes on it. Thanks in Advance,

Chris :)

like image 638
Chris Bacon Avatar asked Sep 20 '10 13:09

Chris Bacon


People also ask

Can C be used for graphics?

Graphics programming in C used to drawing various geometrical shapes (rectangle, circle eclipse etc.), use of mathematical function in drawing curves, coloring an object with different colors and patterns and simple animation programs like jumping ball and moving cars.

Can we do animation in C language?

In this program, we will draw a red color ball move it vertically up and down like a bouncing ball. We will use below mentioned functions in this program.

How do you draw a graphic circle in C?

The header file graphics. h contains circle() function which draws a circle with center at (x, y) and given radius. Syntax : circle(x, y, radius); where, (x, y) is center of the circle.

What is graphics mode in C?

graphicsMode : It is a pointer to an integer that specifies the graphics mode to be used. If *gdriver is set to DETECT , then initgraph sets *gmode to the highest resolution available for the detected driver. driverDirectoryPath : It specifies the directory path where graphics driver files ( BGI files ) are located.


2 Answers

This is a non-trivial, if not impossible task to accomplish with the wmp control in winforms.

I don't know of any way to actually draw on the wmp but you could draw on a transparent panel overlaid over the wmp. This will not work will the video is playing but you can show the drawing while it is paused. I have used this technique to draw over a 3rd party video control that works similarly to wmp.(Edit - this does not seem to work with the wmp control)

However, as real transparent panels are also rather tricky in winforms, another way would be to grab an image from the video and draw on the overlaid image. Again, only when it is paused.

This commercial control does enable drawing over the video. It has an event that fires every frame that you can use to do the drawing. The big downside, though is that you can't really do anything too fancy as your drawing routine needs to finish before the next frame is drawn.

I would strongly encourage you to use WPF(even if its a wpf control hosted within a winforms app) to show your video. It is a whole lot easier to draw on video(including playing video) in wpf.

EDIT

I just tested drawing over the wmp using a transparent panel and its doesn't behave as my 3rd party control did,so I suggest you do the video playing bit in WPF and host that in your winforms app. (I just tested that too using @Callums inkcanvas suggestion and it works like a charm)

like image 165
Geoff Appleford Avatar answered Sep 22 '22 12:09

Geoff Appleford


If you are using WPF, try placing an InkCanvas on top of your video and setting the Background to transparent. You can then save and load up the shapes the users draw on top of the video.

A little proof-of-concept with a picture instead of a video:

alt text

I suspect you may be using WinForms though, where this may be more difficult. If so, a good excuse to learn WPF!


EDIT: With WinForms, you would have to make your own custom control that acts as a transparent overlay and add brush strokes to it. It would be extremely hard to implement well (with transparent background, which doesn't play well with WinForms). I would recommend using WPF if you are still at a stage you can change your application's UI. WPF works on XP and up.


EDIT2: After googling, there are some InkCanvas equivalents that people have made for WinForms, but I have no idea how good they are and may not support transparent backgrounds.

You could always have the video that you want annotated in a new WPF window and the rest of your application in WinForms.

like image 23
Callum Rogers Avatar answered Sep 18 '22 12:09

Callum Rogers