5
我使用codeplex的ImageTools来保存画布为PNG;然而,当我使用writeableBitmap.SaveJpeg()
时,我遇到了同样的问题。因此,问题不在于图像类型,而在于我如何在IsolatedStorage
中进行保存或加载。将图像保存并加载到IsolatedStorage需要保存两次
当我通过按保存按钮保存图像文件存在,但是当我加载图像没有出现。如果我保存图像两次,图像加载并正确显示。
以下是我的代码。
保存文件:
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();
}
}
加载文件
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;
}
}
}
刚刚尝试了你的代码,似乎工作正常,都在模拟器上(诺基亚Lumia 920)... –
奇数。我已经尝试过仿真器和设备(L920,针对Windows Phone 8.0的Visual Studio 2012),并且这两个错误都是持续存在的。不过,谢谢你让我知道它有效。 –