Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

  • Yi-Lun Luo - MSFT

    Yi-Lun Luo -...

    All-Star

    25149 Points

    2759 Posts

    Microsoft

    Re: How to capture a thumbnail image of a video?

    Apr 16, 2008 05:02 AM | LINK

    Hello, you can't do that in Silverlight. You'll have to do that on the server. The simplest way to capture capture a screen shoot is using WPF's RenderTargetBitmap. You will of course need .NET 3.0 or above on the server. Then in your web service application, you can use Process.Start method to start a WPF application. In the WPF application, you can write something like this:

    private MediaPlayer player = new MediaPlayer();

     

    private void Window_Loaded(object sender, RoutedEventArgs e)

    {

    VideoDrawing vd = new VideoDrawing();

    player.Open(new Uri("expressionstudio.wmv", UriKind.Relative));

    vd.Rect = new Rect(0, 0, 300, 300);

    vd.Player = player;

    player.MediaOpened +=
    new EventHandler(player_MediaOpened);

    player.Play();

    //You may want to pass a parameter to the WPF application to indicate which frame you want to capture.

    player.Position =
    TimeSpan.FromSeconds(30);

    }

     

    void player_MediaOpened(object sender, EventArgs e)

    {

    DrawingVisual drawingVisual = new DrawingVisual();

    DrawingContext drawingContext = drawingVisual.RenderOpen();

    drawingContext.DrawVideo(player, new Rect(new Point(0, 0), new Point(300, 300)));

    drawingContext.Close();

    RenderTargetBitmap rtb = new RenderTargetBitmap(300, 300, 96, 96, PixelFormats.Pbgra32);

    rtb.Render(drawingVisual);

    //Do whatever you want with this bitmap and then shutdown the WPF application.

    player.Stop();

    App.Current.Shutdown();

    }

    You can also try to use the WPF APIs directly in the web service application. But I haven't tested that.

    shanaolanxing - I'll transfer to the Windows Azure team, and will have limited time to participate in the Silverlight forum. Apologize if I don't answer your questions in time.