简体   繁体   中英

WPF using byte[] resource as XAML image

How do you add a byte[] resource that's in resources.resx to an XAML image?

I need to know how to do this both from the XAML and in the C#, that's what I've been unable to find.

This article describes how to get an image from a resource file using C#.

To do it directly in the XAML is more difficult, however I have created a MarkupExtension to handle just this situation: https://github.com/brschwalm/Vienna .

Note: when you say a byte[] resource, do you mean an image/icon in a resource file, or an actual byte array?

If you have your image defined like this:

<Image Source="{Binding ImageSource}" ... />

The following will update it:

this.ImageSource = new BitmapImage();
this.ImageSource.BeginInit();
this.ImageSource.StreamSource = new MemoryStream(byteArray);
this.ImageSource.EndInit();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM