In the code below, I am trying to get a images from a MediaPlayer
from different timestamps (in clearestThumbnails
), but in my binding in the UI, I only see the images from the first timestamp. For example, when I do Thumbnails[5]
, it will still return to me the image from the first timestamp. I don't think my binding is the issue, as my other objects appear okay.
There seems to be a problem when the DrawingContext
tries to draw the video image from it's current position. Moreover, is it good practice to be creating new DrawingVisual
s with every new image? Is this why I'm having this issue?
foreach (var k in clearestThumbnails.Keys)
{
player.Play();
player.Position = clearestThumbnails[k];
player.Pause();
var visual = new DrawingVisual();
using (var context = visual.RenderOpen())
{
context.DrawVideo(player, new System.Windows.Rect(0, 0, 250, 200));
}
var bitmap = new RenderTargetBitmap(250, 200, 96, 96, PixelFormats.Pbgra32);
bitmap.Render(visual);
Thumbnails.Add(bitmap);
}
I'll just post it here in case someone will ever need the answer. It's a little rudimentary, but it works good enough for my purposes. All I needed was to put Thread.Sleep(100);
inside the for-loop.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.