0
votes

I'm trying to get an image from URL and save it to the isolated storage and than to get it from the isolated storage and display it with in my WP-7 app.

Here is the relavant code:

public void GetImages()
{
    string uri = "http://sherutnetphpapi.cloudapp.net/mini_logos/" + path;
    WebClient m_webClient = new WebClient();
    imageUri = new Uri(uri);

    m_webClient.OpenReadCompleted += new OpenReadCompletedEventHandler(webClient_ImageOpenReadCompleted);
    m_webClient.OpenReadAsync(imageUri);
}

void webClient_ImageOpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{

    Stream stream = e.Result;
    using (IsolatedStorageFile myIsf = IsolatedStorageFile.GetUserStoreForApplication())
    {
        IsolatedStorageFileStream fileStream = myIsf.CreateFile(path);
        StreamResourceInfo sri = null;
        sri = Application.GetResourceStream(imageUri);

        BitmapImage bitmap = new BitmapImage();
        bitmap.SetSource(sri.Stream);
        WriteableBitmap wb = new WriteableBitmap(bitmap);

        // Encode WriteableBitmap object to a JPEG stream.

        System.Windows.Media.Imaging.Extensions.SaveJpeg(wb, fileStream, wb.PixelWidth, wb.PixelHeight, 0, 85);
        fileStream.Close();
    }
}

The problem is at this line: sri = Application.GetResourceStream(imageUri); I get an exception on this method GetResourceStream() Expected relative Uri, found absolute.

I dont understand what to give this method instead of the imageUri.

Thanks in advance!!

2
I really don't know what that is I'm new on this website. I'll be happy if you can explain me about this rate - thechmodmaster
O.k i think i got it.....thanks - thechmodmaster
When people have provided helpful answers, they get up-votes. When the answers aren't helpful, they get down-votes. Whichever answer you feel helped you the most, or was the most accurate, you need to accept it as "the correct answer". - Chris Gessler

2 Answers

2
votes

I think this might be what you need.

public void GetImages()   
{   
    string uri = "http://sherutnetphpapi.cloudapp.net/mini_logos/" + path;      
    WebClient m_webClient = new WebClient();   
    imageUri = new Uri(uri);   
    m_webClient.OpenReadAsync(imageUri);  
    m_webClient.OpenReadCompleted += new OpenReadCompletedEventHandler(webClient_ImageOpenReadCompleted);   
    m_webClient.AllowReadStreamBuffering = true;  

} 


void webClient_ImageOpenReadCompleted(object sender, OpenReadCompletedEventArgs e) 
{        
    var isolatedfile = IsolatedStorageFile.GetUserStoreForApplication(); 
    using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(path, System.IO.FileMode.Create, isolatedfile)) 
    { 
        byte[] buffer = new byte[e.Result.Length]; 
        while (e.Result.Read(buffer, 0, buffer.Length) > 0) 
        { 
            stream.Write(buffer, 0, buffer.Length); 
        } 
    }
}
0
votes

What do this path contains, because if it contains an relative url, then remove / from path. Since you already has / at the end of uri.