1

I want to Video File thumbnail. Get Video path and convert to Image. Then convert to bmp, and save the bmp as an image file. If this is possible, please show me a way.

private void add_Video_Image(string sFullname_Path_of_Video)
    {
        //*create mediaplayer in memory and jump to position 
        MediaPlayer mediaPlayer = new MediaPlayer();

        mediaPlayer.MediaOpened += new EventHandler(mediaplayer_OpenMedia);
        mediaPlayer.ScrubbingEnabled = true;
        mediaPlayer.Open(new Uri(sFullname_Path_of_Video));
        mediaPlayer.Position = TimeSpan.FromSeconds(0);
    }

    private void mediaplayer_OpenMedia(object sender, EventArgs e)
    {
        MediaPlayer mediaPlayer = sender as MediaPlayer;
        DrawingVisual drawingVisual = new DrawingVisual();
        DrawingContext drawingContext = drawingVisual.RenderOpen();
        drawingContext.DrawVideo(mediaPlayer, new Rect(0, 0, 160, 100));
        drawingContext.Close();

        double dpiX = 1 / 200;
        double dpiY = 1 / 200;
        RenderTargetBitmap bmp = new RenderTargetBitmap(160, 100, dpiX, dpiY, PixelFormats.Pbgra32);
        bmp.Render(drawingVisual);

        Image newImage = new Image();
        newImage.Source = bmp;
        newImage.Stretch = Stretch.Uniform;
        newImage.Height = 100;

        //save bmp to image
    }
ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86

1 Answers1

-1

Please check this link. It holds the answer to your question: Easiest way of saving wpf Image control to a file You can do the save prior to setting the 'RenderTargetBitmap' to the 'Image Control'.

Lupu Silviu
  • 1,145
  • 11
  • 23
  • I just want to open video file and it convert to >>image file(video preview or video thumbnail) in my DebugFolder< –  Jul 04 '19 at 13:13
  • 1
    Thanks to Lupu Silviu, I was able to create a video thumbnail and apply it to listbox. –  Jul 09 '19 at 06:07