Question

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

Was it helpful?

Solution

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);

OTHER TIPS

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).

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.

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