Image 保存图像并将其加载到IsolatedStorage需要保存两次
为了将画布保存为png,我使用了FromCodePlex;但是,当我使用Image 保存图像并将其加载到IsolatedStorage需要保存两次,image,windows-phone-8,isolatedstorage,Image,Windows Phone 8,Isolatedstorage,为了将画布保存为png,我使用了FromCodePlex;但是,当我使用writeableBitmap.SaveJpeg()时,我遇到了同样的问题。因此,问题不在于图像类型,而在于如何在IsolatedStorage中保存或加载图像 当我按保存按钮保存图像时,文件存在,但当我加载图像时,什么也不显示。如果我保存图像两次,则图像将加载并正确显示 下面是我的代码 保存文件: ExtendedImage myImage = myCanvas.ToImage(); using (var isoStor
writeableBitmap.SaveJpeg()时,我遇到了同样的问题。因此,问题不在于图像类型,而在于如何在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;
}
}
}
尝试使用此代码从isoStore
检索图像。它对我有用
using (IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication())
{
if (iso.FileExists(string.Format("image.png")))
{
string fileName = "image.png";
string filePath = iso.GetType().GetField("m_RootDir", System.Reflection.BindingFlags.NonPublic |
System.Reflection.BindingFlags.Instance).GetValue(iso).ToString() + fileName;
}
}
您可以将映像的源设置为filePath,这样访问它就不会有任何问题
如果这不起作用,那么问题是在保存图像时。您可能需要找到一种将画布保存为png或jpeg的解决方法。刚刚尝试了您的代码,并且似乎工作正常,无论是在emulator上还是在设备上(诺基亚Lumia 920)…奇怪。我在emulator和设备(L920,针对Windows Phone 8.0的Visual Studio 2012)上都进行了尝试,但错误在这两个设备上都持续存在。不过,谢谢你让我知道它是有效的。