0

i am trying to make a simple application in which i have an image i have copied it in Assets folder of my project. The image i got from the web, and it is in the png format.

can some body give me an idea that how i can copy my images to my project so that when i deploy the project on device i will able to load them.

Current i what i am trying is.

   var streamResource = App.GetResourceStream(new Uri("/Assets/Tiles/gradiant-mask.png", UriKind.Relative));
                    using (Stream stream = streamResource.Stream) {
                        var maskData = new byte[stream.Length];
                        stream.Read(maskData, 0, maskData.Length);
}

But i always get the streamResource object as null and the may be the reason is it didn't find the file on the device. can some body guide me that how i can load the image on the device in my wp8 application.

Madu
  • 4,849
  • 9
  • 44
  • 78

2 Answers2

0

Make sure the Build action is set to Content on the properties of the image file in Visual Studio.

If you want the Build action to be set to Resource, use the following URI syntax:

new Uri("/YOUR_PROJECT_NAME;component/Assets/Tiles/gradiant-mask.png", UriKind.Relative)

Using the Content build action is recommended.

Olivier Payen
  • 15,198
  • 7
  • 41
  • 70
  • i am still getting the same `null` value in the resource stream. what i am doing now is some thing like this : var rStream = App.GetresourceStrea(new Uri("/PhoneApp4;component/Assets/Tiles/gradiant-mask.png", UriKind.Relative)); but no benefits. any idea? and what do you mean by Build action to be set to Resource ??? – Madu Jul 18 '13 at 09:54
  • In VS Solution Explorer, right click on the image file => Properties => Build action. – Olivier Payen Jul 18 '13 at 10:11
0

you can directly load image by :
in XAML

Source="/Assets/Tiles/gradiant-mask.png"

or in code behind by

imagename.Source = new Uri("/Assets/Tiles/gradiant-mask.png",UriKind.Relative);

set the build action as content .

Arul Dinesh
  • 550
  • 4
  • 15
Sandeep Chauhan
  • 1,313
  • 1
  • 10
  • 23
  • i actually want to do some editing on image and that's why i want stream from the image file. I do not want to load it in some image control. – Madu Jul 18 '13 at 08:54