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?
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.
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
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With