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!!
I think this might be what you need.