Save image to isolated storage

Possible duplicate:
store the image in isolated storage on a Windows 7 phone

I use Visual Studio / Expression Blend to create my application for a Windows 7 phone. The user must be able to select the image that he / she wants to edit, and after editing the user can click the "Save" button and the specific edited image will be saved in isolated storage. But I can’t save the image in isolated storage from a button click event.

Does anyone have some sample code on how to do this? Thank!

My codes for the button:

using (var isoStore = IsolatedStorageFile.GetUserStoreForApplication()) 

{ 

var bi = new BitmapImage(); bi.SetSource(pic); 

var wb = new WriteableBitmap(lion.jpg,lion.jpg.RenderTransform); 

using (var isoFileStream = isoStore.CreateFile("somepic.jpg")) 

{ 

var width = wb.PixelWidth; 

var height = wb.PixelHeight;

Extensions.SaveJpeg(wb, isoFileStream, width, height, 0, 100); 

 } 
}
+3
source share
1 answer

IsolatedStorage PhotoChooserTask, ( e ):

public static void SaveImage(Stream imageStream, string fileName, int orientation, int quality)
{
    using (var isolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
    {
        if (isolatedStorage.FileExists(fileName))
            isolatedStorage.DeleteFile(fileName);

        IsolatedStorageFileStream fileStream = isolatedStorage.CreateFile(fileName);
        BitmapImage bitmap = new BitmapImage();
        bitmap.SetSource(imageStream);

        WriteableBitmap wb = new WriteableBitmap(bitmap);
        wb.SaveJpeg(fileStream, wb.PixelWidth, wb.PixelHeight, orientation, quality);
        fileStream.Close();
    }
}
+7

All Articles