Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is wrong with this URI?

Tags:

c#

wpf

Hej

I am trying to load an (embedded) image in a wpf application, using an Uri but I keep getting an exception.

The code is:

new BitmapImage(new Uri("pack://application:,,,,/Icons/m.png"));

(In case it isn't clear, I am trying to load the m.png file from the Icons folder, which has been marked as an embedded ressource).

and the exception is

NotSupportetException (the URI prefix is not recognized)

Can anybody tell me what the uri should have been?

like image 378
tomjen Avatar asked Jul 12 '10 07:07

tomjen


2 Answers

Three commas must be instead of four in your string:

new BitmapImage(new Uri("pack://application:,,,/LibName;component/Icons/m.png"));

LibName - points to assembly where resource is hosted.

like image 150
Eugene Cheverda Avatar answered Sep 21 '22 08:09

Eugene Cheverda


You may take a look at this blog post. The solution is to register a custom uri parser so that it recognizes the pack protocol:

UriParser.Register(
    new GenericUriParser(GenericUriParserOptions.GenericAuthority), "pack", -1
);
like image 37
Darin Dimitrov Avatar answered Sep 17 '22 08:09

Darin Dimitrov