81 8

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;"
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