by
81 7
0
4
63
0
Tagged
Specified
Refined
OpenSource

Published on:

ArchitectureAny
FrameworkUWP
InputName0imageUri
InputType0Uri
Languagecsharp
LicenseMIT_X11
MethodNameToByteArrayImage
OutputTypeTask<byte[]>

UWP: retrieve the binary content of a file, given its URL

This is meant to be used with images, but can be applied to any kind of binary content...
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/4361251/UWP--retrieve-the-binary-content-of-a-fi?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<byte[]> ToByteArrayImage(this Uri imageUri) { RandomAccessStreamReference streamRef = RandomAccessStreamReference.CreateFromUri(imageUri); IRandomAccessStreamWithContentType streamWithContent = await streamRef.OpenReadAsync(); byte[] buffer = new byte[streamWithContent.Size]; await streamWithContent.ReadAsync(buffer.AsBuffer(), (uint)streamWithContent.Size, InputStreamOptions.None); return buffer; }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus