开发者

Silverlight - Load Image with FileStream

I have a Silverlight application t开发者_运维技巧hat I want to show pictures in. The pictures are loaded from a database into FileStream objects. I need to load these FileStream objects into a System.Windows.Image element so they are shown in my Silverlight application. The problem is, I cannot figure out how to set the Source of an Image to a FileStream. Does anyone know how to do this?

Thank you!


This should work. I actually put something like this in an attached property so I can decorate images in xaml with our image identifier. The attached property also does some caching of images in the local application store.

var image = d as Image;
if(image != null)
{
    var bitMap = new BitmapImage();
    byte[] buffer = new byte[e.Result.Length];
    e.Result.Read(buffer, 0, (int) e.Result.Length);
    var stream = new MemoryStream(buffer);
    bitMap.SetSource(stream);
    image.Source = bitMap;
}

Cheers!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜