简体   繁体   中英

Image URI not displaying the image in C#

I'm working on a project to develop a UWP app using C#. I've used the following code to assign an image to the page.

CarImageDisplay.Source = new BitmapImage(new Uri(param[7]));  

Here the value of param[7] is set as:

string imgpath = @"C:\Users\ADMIN\Documents\Visual Studio 2015\Projects\JijoyProjectv2\JijoyProjectv2\Assets\Maruti-Alto.jpg";

The app returns no runtime error but the image is not displayed on the page. Please suggest something.

Thanks

Your UWP app lives inside a "sandbox", so it's not possible for it to directly to point to file located in your computer.

Here's a good guide on MSDN which shows how to load resources: How to load file resources (XAML)

If the image lives inside your app package, you should be able to point to it using ms-appx: scheme. For example:

var uri = new System.Uri("ms-appx:///Assets/Maruti-Alto.jpg");

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