1

i am developing a WP 8 application and i want to load an image which is currently on my computer drive. Here is my Code

  try
        {
            using (FileStream fileStream = File.OpenRead("\\TiltFilter\\FilterEffects\\Assets\\AlignmentGrid.png")) 
            {
                MemoryStream memStream = new MemoryStream();
                memStream.SetLength(fileStream.Length);
                fileStream.Read(memStream.GetBuffer(), 0, (int)fileStream.Length);
            }
        }
        catch (Exception e)
        {
            string str = e.Message;
        }

It gives me exception that of Type

System.Io.DirectoryNotFoundexceptionand the message isCould not find a part of the path 'C:\TiltFilter\FilterEffects\Assets\AlignmentGrid.png'.

Can some body help me that how i can load the image in memorystream on WP8

Thanks

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Madu
  • 4,849
  • 9
  • 44
  • 78
  • Yes that's right. So how i can load the image from my Assets folder in WP 8 application – Madu Jun 25 '13 at 08:09
  • I'd suggest the same that Paul has suggested below. You could even make it part of the project's content files so that it automatically gets copied every time you deploy the application. If this is a one time operation, manual copying may be far faster. – dotNET Jun 25 '13 at 08:50

3 Answers3

5

You need to add an image to your project as Content and use GetResourceStream to access a stream of an image:

var resource = App.GetResourceStream(new Uri("Assets/AlignmentGrid.png", UriKind.Relative));
var buffer = new byte[resource.Stream.Length];
resource.Stream.Read(buffer, 0, buffer.Length);
Pavel Saniuk
  • 788
  • 5
  • 11
  • Also change the properties of the image in Vs studio to Content. And also set the property of "Copy to OutPut directory" to "Copy if newer". – Madu Jul 18 '13 at 10:44
  • Thanks! This helped me out trying to copy a local text file in the application load to a MemoryStream. MemoryStream ms = new MemoryStream(); resource.Stream.CopyTo(ms); I kept getting hung up because I wasn't setting the text file property to "Content" before building. – Rob.Kachmar Jul 27 '14 at 20:20
0

The phone doesn't understand UNC network paths - it doesn't support the SMB protocol which Windows File Servers use.

You will either need to package up the file so that it is part of the application package (.xap file) and is local to the phone or serve up the assets using a Web Server (i.e. using the http:// protocol).

The first option is obviously the most robust as it doesn't require that the phone has a network connection to your server.

For an example of how to do this, see this blog post for the difference between packaging "Content" and "Resource" files (it mentions XML files, but the concepts are the same for any file type).

Paul Annetts
  • 9,554
  • 1
  • 27
  • 43
0

A Windows phone app can only access the it's own Isolated Storage, and the SD Card

http://msdn.microsoft.com/en-us/library/windowsphone/develop/ff402541%28v=vs.105%29.aspx

If you want to share files between Pc and Phone you can use a webservice.

D.Rosado
  • 5,634
  • 3
  • 36
  • 56