开发者

Silverlight. Writable bitmap. Makes bad images from still video. Is there a workaround?

I have code like this:

            MediaElement me = myPlayer.MediaE开发者_如何学编程lement;
            WriteableBitmap wb = new WriteableBitmap(me.NaturalVideoWidth, me.NaturalVideoHeight);
            wb.Render(me, null);

I want make thumbnails from video in run-time. It works fine with one little quirk. When video in the media element is paused the bitmap image comes broken. Like a corrupted jpeg. Sometime it is black square with some random coloured dots...

I think it is Silverlight bug. My question - is there a workaround?


By very chance I found what is wrong... I googled the solution above, verified it with several blogs and silverlight.net forums. I spent 40 min reading all those community giants publications trying to find what could be wrong in 3 lines of code. Everything pointed that this should work. And it does work.. Sometime...

However when I try to make picture of still media element it doesnt work 9 times out of 10..

the solution is dead simple.

        MediaElement me = myPlayer.MediaElement;
        WriteableBitmap wb = new WriteableBitmap(me.NaturalVideoWidth, me.NaturalVideoHeight);
        wb.Render(me, null);
        image.Source = wb;
        **wb.Invalidate();**
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜