by
81 7

UWP: turn byte array into image

Given a byte array, let's turn it into an Image that can be used in UWP UI contexts.
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/4361250/UWP--turn-byte-array-into-image?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
public static async Task<Image> ToImage(this byte[] input) { if (input == null) return null; BitmapImage biSource = new BitmapImage(); using (InMemoryRandomAccessStream stream = new InMemoryRandomAccessStream()) { await stream.WriteAsync(input.AsBuffer()); stream.Seek(0); await biSource.SetSourceAsync(stream); } return new Image { Source = biSource }; }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus