0

I want to display an Image in a StackPanel from a base64 string but it's not working correctly.

string base64encodedImage = el.Value;
byte[] imageData = Convert.FromBase64String(base64encodedImage);

Image imageSection = new Image();
BitmapImage image = new BitmapImage();

using (MemoryStream memStream = new MemoryStream(imageData))
{
    image.BeginInit();
    image.StreamSource = memStream;
    image.EndInit();
}

imageSection.Source = image;

panel.Children.Add(imageSection);

Example Base64 Image:

iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==

The BitmapImage gets a width and height, the Image however does not and nothing is displayed, what am I doing wrong?

4

1 回答 1

0

请参阅这篇文章以找到获取BitmapImagefrom 字节数组的正确方法。

于 2013-07-01T15:42:51.427 回答