What is wrong with this URI?

Hay

I am trying to load a (embedded) image into a wpf application using Uri, but I get an exception anyway.

The code:

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

(If this is not clear, I try to download the m.png file from the Icons folder, which is marked as an embedded resource).

and exception

 NotSupportetException (the URI prefix is not recognized) 

Can someone tell me what was supposed to be uri?

+6
c # wpf
source share
2 answers

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

 UriParser.Register( new GenericUriParser(GenericUriParserOptions.GenericAuthority), "pack", -1 ); 
+2
source share

Three commas should be instead of four in your line:

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

LibName - indicates the assembly where the resource is located.

+4
source share

All Articles