简体   繁体   中英

Read stream from absolute uri

How to GetResourceStream from absolute uri.

When I am running the below code I am getting null in sri.

StreamResourceInfo sri = Application.GetResourceStream(new Uri("http://----", UriKind.RelativeorAbsolute));
BitmapImage src = new BitmapImage();
src.SetSource(sri.Stream);
// Get WriteableBitmap
WriteableBitmap bitmap = new WriteableBitmap(src);

Any help is highly appreciated.

GetResourceStream method is not for http requests. See the documentation here.

Returns a resource file from a location in the application package.

uriResource Type: System.Uri A relative URI that identifies the resource file to be loaded. If the file has a Build Action of Content, the URI is relative to the application package and you should not use a leading forward slash. If the file has a Build Action of Resource , you can use a leading forward slash, but it is not required.

Resource data is a data compiled into your assembly/package

Basically, there are two types of resources which you can load via that method:

  • Files Embedded in the application assembly in the application package Uri("/Application;component/EmbeddedInApplicationAssembly.png")

  • Files included in the application package Uri("IncludedInApplicationPackage.png");

What you're looking for is HttpClient

https://blogs.msdn.microsoft.com/bclteam/2013/02/18/portable-httpclient-for-net-framework-and-windows-phone/

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