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?

eric.itzhak
  • 15,752
  • 26
  • 89
  • 142
  • 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`)? – Vlad Feb 23 '12 at 20:37
  • Yes to all and it's a resource – eric.itzhak Feb 24 '12 at 12:34

2 Answers2

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)));
thumbmunkeys
  • 20,606
  • 8
  • 62
  • 110
eric.itzhak
  • 15,752
  • 26
  • 89
  • 142
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.

MethodMan
  • 18,625
  • 6
  • 34
  • 52
yo chauhan
  • 12,079
  • 4
  • 39
  • 58
  • 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. – eric.itzhak Feb 24 '12 at 12:35