Save the image to IsolatedStorage:
Private void btnSave_Click (object sender, RoutedEventArgs e)
{
WebClient wc = new WebClient ();
Wc. OpenReadCompleted + = new OpenReadCompletedEventHandler (wc_OpenReadCompleted );
Wc. OpenReadAsync (new Uri ("http://php.weather.sina.com.cn/images/yb3/180_180/qing_0.png", UriKind. RelativeOrAbsolute ));
}
Void wc_OpenReadCompleted (object sender, OpenReadCompletedEventArgs e)
{
IsolatedStorageFile myStore = IsolatedStorageFile. GetUserStoreForApplication ();
MyStore. CreateDirectory ("Images ");
If (myStore. FileExists ("Images "))
{
MyStore. DeleteFile ("Images ");
}
// Read the image stream first, and then save the image as png:
Byte [] _ imgBytes = new byte [e. Result. Length];
E. Result. Read (_ imgBytes, 0, _ imgBytes. Length );
Using (IsolatedStorageFile storage = IsolatedStorageFile. GetUserStoreForApplication ())
{
Using (Stream stream = storage. OpenFile ("Images/sun.png", FileMode. Create ))
{
Stream. Write (_ imgBytes, 0, _ imgBytes. Length );
MessageBox. Show ("Image Storage successful! ");
}
}
}
Reading images from IsolatedStorage (same as reading images from jpg):
Private void btnRead_Click (object sender, RoutedEventArgs e)
{
BitmapImage bi = new BitmapImage ();
Using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile. GetUserStoreForApplication ())
{
Using (IsolatedStorageFileStream fileStream = myIsolatedStorage. OpenFile ("Images/sun.png", FileMode. Open, FileAccess. Read ))
{
Bi. SetSource (fileStream );
This. imgPic. Height = bi. PixelHeight;
This. imgPic. Width = bi. PixelWidth;
}
}
This. imgPic. Source = bi;
}
Reference: http://www.itivy.com/wp7/archive/2011/11/17/windows-phone-save-and-load-image.html