I am using ImageTools from codeplex in order to save a canvas as a png; however, I had the same problem when I was using a writeableBitmap.SaveJpeg()
. Therefore, the problem is not with the image type, but rather with how I am saving or loading in IsolatedStorage
.
When I save the image by pressing a save button the file exists, but when I load the image nothing appears. If I save the image twice then the image loads and is displayed correctly.
Below is my code.
Saving File:
ExtendedImage myImage = myCanvas.ToImage();
using (var isoStore = IsolatedStorageFile.GetUserStoreForApplication())
{
if (isoStore.FileExists("image.png"))
isoStore.DeleteFile("image.png");
using (var fileStream = isoStore.CreateFile("image.png"))
{
myImage.WriteToStream(fileStream, "image.png");
fileStream.Close();
}
}
Loading file
BitmapImage bi = new BitmapImage();
using (var isoStore = IsolatedStorageFile.GetUserStoreForApplication())
{
if (isoStore.FileExists("image.png"))
{
using (var fileStream = isoStore.OpenFile("image.png", FileMode.Open))
{
bi.SetSource(fileStream);
this.img.Height = bi.PixelHeight;
this.img.Width = bi.PixelWidth;
this.img.Source = bi;
}
}
}