Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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 .

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top