WPF image.source change during runtime, from byte[]. But image is blank(white)
I am tryi开发者_运维技巧ng to change an image for image1
during runtime. However the image turns blank(blank), what am I doing wrong?
ImageAsBytes
is a Byte[]
containing an image.
ScrollViewer1
is the where image1
is located.
using (MemoryStream ms = new MemoryStream(ImagesAsBytes, 0, ImagesAsBytes.Length))
{
BitmapImage image = new BitmapImage();
image.BeginInit();
image.StreamSource = ms;
image.EndInit();
}
image1.Source = image;
scrollViewer1.UpdateLayout();
I think your Image can't be displayed because the MemoryStream you are using is being disposed. Remove the surrounding using
block and see if that helps. (you would need to dispose of the stream manually if you don't need it anymore then)
精彩评论