Windows phone 7 如何在windows phone上将图像从独立存储加载到图像控件中?

Windows phone 7 如何在windows phone上将图像从独立存储加载到图像控件中?,windows-phone-7,isolatedstorage,Windows Phone 7,Isolatedstorage,我使用此代码在相机操作完成时将图像存储到隔离存储器中 void摄影机\u已完成(对象发送器,照片结果e) { BitmapImage objImage=新的BitmapImage(); //objImage.SetSource(如ChosenPhoto); //Own_Image.Source=对象图像; 使用(var isolatedStorage=IsolatedStorageFile.GetUserStoreForApplication()) { fnam=e.OriginalFileNa

我使用此代码在相机操作完成时将图像存储到隔离存储器中

void摄影机\u已完成(对象发送器,照片结果e)
{
BitmapImage objImage=新的BitmapImage();
//objImage.SetSource(如ChosenPhoto);
//Own_Image.Source=对象图像;
使用(var isolatedStorage=IsolatedStorageFile.GetUserStoreForApplication())
{
fnam=e.OriginalFileName.Substring(93);
MessageBox.Show(fnam);
if(isolatedStorage.FileExists(fnam))
isolatedStorage.DeleteFile(fnam);
IsolatedStorageFileStream fileStream=isolatedStorage.CreateFile(fnam);
BitmapImage位图=新的BitmapImage();
位图.SetSource(如ChosenPhoto);
WriteableBitmap wb=新的WriteableBitmap(位图);
SaveJpeg(fileStream,wb.PixelWidth,wb.PixelHeight,100100);
MessageBox.Show(“创建的文件”);
fileStream.Close();
}
}
现在我想从独立存储中获取图像,并将其显示在图像控件中

有可能吗?

类似这样的事情:

public BitmapImage LoadImageFromIsolatedStorage(字符串路径){
var isf=IsolatedStorageFile.GetUserStoreForApplication();
使用(var fs=isf.OpenFile(path,System.IO.FileMode.Open)){
var image=新的位图图像();
image.SetSource(fs);
返回图像;
}
}
在代码中

image1.Source=loadimagefromsolatedstorage(“image.jpg”);

是的。您可以使用此功能从IsolatedStorage加载图像:

私有静态位图图像GetImageFromIsolatedStorage(字符串imageName)
{
var bimg=新的位图图像();
使用(var iso=IsolatedStorageFile.GetUserStoreForApplication())
{
使用(var stream=iso.OpenFile(imageName,FileMode.Open,FileAccess.Read))
{
bimg.SetSource(流);
}
}
返回bimg;
}
用法:

ImageControl.Source=GetImageFromIsolatedStorage(fnam);
检查此代码段

public static void SaveImage( string name)
{


}

它工作正常。我移动下一页做一些操作。回到这个老屏幕。此处不显示加载的图像。我在page_加载的事件中编写了相同的函数调用。为什么没有再次加载。使用(var isolatedStorage=IsolatedStorageFile.GetUserStoreForApplication()){if(isolatedStorage.FileExists(fnam)){Own_Image.Source=getimagefromsolatedstorage(fnam);}
var bitmap = new BitmapImage();
bitmap.SetSource(attachmentStream);
var wb = new WriteableBitmap(bitmap);
var temp = new MemoryStream();
wb.SaveJpeg(temp, wb.PixelWidth, wb.PixelHeight, 0, 50);

using (var myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
    if (!myIsolatedStorage.DirectoryExists("foldername"))
    {
        myIsolatedStorage.CreateDirectory("foldername");
    }

    var filePath = Path.Combine("foldername", name + ".jpg");

    using (IsolatedStorageFileStream fileStream = new IsolatedStorageFileStream(filePath, FileMode.Create, myIsolatedStorage))
    {
        fileStream.Write(((MemoryStream)temp).ToArray(), 0, ((MemoryStream)temp).ToArray().Length);
        fileStream.Close();
    }
}