I fail to access Resource image file from code in WPF using pack Uri
Asked Answered
P

2

4

I have some image resources in my app i want to access programaticly.

Now i'm based on some source code so i need to acess via Uri so my code is :

new BitmapImage(new Uri("pack://application:,,,/YearBook;component/Resources/Output/" + i.ToString() + ".jpg", UriKind.RelativeOrAbsolute));

though when i try to access it i get error that resources not found ( and the name is right)

Anyone knows why?

EDIT:

Might be i needed to add some assembly in the assembly file?

Purr answered 23/2, 2012 at 20:29 Comment(2)
You need to provide more information. Is the assembly YearBook available? Are the images embedded into the assembly as "resource" or "embedded resource"? (Only one of the two is correct, not sure which exactly.) Is the assembly YearBook located in the same folder as the executable (or in a subfolder YearBook)?Hilda
Yes to all and it's a resourcePurr
P
4

In the end with all types of ways to approach this resource, my problem was i forgot 1 folder in the sub folders.

This code eventually worked :

new BitmapImage(new Uri("pack://application:,,,/Resources/Images/Output/" 
+ i.ToString() + ".jpg", UriKind.Absolute)));
Purr answered 24/2, 2012 at 13:27 Comment(0)
H
0
StreamResourceInfo resource = Application.GetResourceStream(
new Uri("SilverlightApp1;component/embedded.png", UriKind.Relative));

SilverlightApp1 is assembly name,component is keyword .You will get your resource and then cast it to appropriate type, Hope this will help.

Hydrargyrum answered 23/2, 2012 at 20:44 Comment(1)
in the end it needs to be BitmapImage, i tried setting Stream of a bmp to an stream from the essambly but that failed to work, it would be easier getting a the uri of a resource, how can i cast it? By the way, when i try your code i get the same error.Purr

© 2022 - 2024 — McMap. All rights reserved.