开发者

WPF image.source change during runtime, from byte[]. But image is blank(white)

开发者 https://www.devze.com 2023-03-11 23:38 出处:网络
I am tryi开发者_运维技巧ng to change an image for image1 during runtime. However the image turns blank(blank), what am I doing wrong?

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)

0

精彩评论

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

关注公众号