0
votes

I need to load a png stored in my asp.net mvc project into my program as a bitmap image. However, the constructor for BitmapImage only takes a Uri object. How can I access the image?

Doing something like

new Uri(VirtualPathUtility.ToAbsolute("~\\Content\\image.png"))

tells me that the format of the URI could not be determined. However it works if I hard code the path (C:\\...etc.)

2

2 Answers

1
votes

You would likely want to Map the relative path that you have to the physical path on the server, to do that you can use Server.MapPath();

http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.mappath.aspx

1
votes

As Stefan pointed out, you can use the MapPath method.

new Uri(Server.MapPath("~/Content/image.png"))