If you want Snapshoot Save as an image or Image It is not impossible to display the control content.
Go directlyCodeFirst, createMediaelementControl,SourceAttribute to set the video path andPositionAttribute.Seek.
<Mediaelement name = "video" loadedbehavior = "pause" opacity = "1" scrubbingenabled = "true"
Source = "C:" users "public" videos "sample Videos" bear. wmv" Position = "0: 5"/>
InButtonOfClickIn the response function,
Private void button_click (Object sender, routedeventargs E)
{
Filestream stream = file. Open ("bear.png", filemode. Create );
Rendertargetbitmap BMP = new rendertargetbitmap (INT) This. Video. actualwidth,
(INT) This. Video. actualheight, 96, 96, pixelformats. pbgra32 );
BMP. Render (this. Video );
Pngbitmapencoder coder = new pngbitmapencoder ();
Coder. interlace = pnginterlaceoption. off;
Coder. frames. Add (bitmapframe. Create (BMP ));
Coder. Save (Stream );
Stream. Close ();
}
We useRendertargetbitmapOfRenderMethod, SetVisualConvert the object to a bitmap before usingXxxbitmapencoderSave as an image file, or directlyRendertargetbitmapAssignedImageControl.
If we are not usingMediaelementControl, but useMediaplayer, We need to use (2) To createDrawingvisualObject, useDrawingcontextOfDrawvideoMethod To play the video.DrawingvisualConverts an object to a bitmap.
The approximate code is as follows:
Void windowreceivloaded (Object sender, routedeventargs E)
{
_ Visual = new drawingvisual ();
Drawingcontext Dc = _ visual. renderopen ();
Mediaplayer player = new mediaplayer ();
Player. Open (New uri (@ "C:" users "public" videos "sample Videos" bear. wmv "));
Player. Position = timespan. fromseconds (5 );
Player. scrubbingenabled = true;
Player. Pause ();
DC. drawvideo (player, new rect (0, 0, _ desiresize. Width, _ desiresize. Height ));
DC. Close ();
}
Private void button_click (Object sender, routedeventargs E)
{
Filestream stream = file. Open ("bear.png", filemode. Create );
Rendertargetbitmap BMP = new rendertargetbitmap (INT) _ desiresize. Width,
(INT) _ desiresize. Height, 96, 96, pixelformats. pbgra32 );
BMP. Render (_ visual );
Pngbitmapencoder coder = new pngbitmapencoder ();
Coder. interlace = pnginterlaceoption. off;
Coder. frames. Add (bitmapframe. Create (BMP ));
Coder. Save (Stream );
Stream. Close ();
}
Drawingvisual _ visual = NULL;
Size _ desiresize = new size (400,300 );
the reason why the drawingvisual object is in loaded the event is created because you need to load the video in advance. If click when an event is created, the saved bitmap is black because the video has not been loaded successfully.