抱歉不清楚,我想要的只是一种查看我的应用程序拍摄的最新照片的方法
示例相机应用程序将照片保存到相机胶卷以及应用程序隔离存储中。这是他们使用的代码 sn-p。
// Save photo as JPEG to the local folder.
using (IsolatedStorageFile isStore = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream targetStream = isStore.OpenFile(fileName, FileMode.Create, FileAccess.Write))
{
// Initialize the buffer for 4KB disk pages.
byte[] readBuffer = new byte[4096];
int bytesRead = -1;
// Copy the image to the local folder.
while ((bytesRead = e.ImageStream.Read(readBuffer, 0, readBuffer.Length)) > 0)
{
targetStream.Write(readBuffer, 0, bytesRead);
}
}
}
如您所见,他们使用文件名fileName 保存它,因此您所要做的就是在您使用的所有fileName 中保留一个List<string>。每次保存新图像时,您都希望将 fileName 添加到列表中。
您可以使用 ApplicationSettings 保存列表
if (!IsolatedStorageSettings.ApplicationSettings.Contains("recent_images"))
{
IsolatedStorageSettings.ApplicationSettings.Add("recent_images", YOUR_LIST);
}
IsolatedStorageSettings.ApplicationSettings.Save();
这样下次你加载应用程序时,你可以再次获得列表(所以基本上你已经墓碑化了列表)
List<string> recent_images = (List<string>) IsolatedStorageSettings.ApplicationSettings["recent_images"];
现在加载您最近的图片
<!-- create the container in xaml -->
<Image x:Name="myImage"></Image>
// this function loads an image from isolated storage and returns a bitmap
private static BitmapImage GetImageFromIsolatedStorage(string imageName)
{
var bimg = new BitmapImage();
using (var iso = IsolatedStorageFile.GetUserStoreForApplication())
{
using (var stream = iso.OpenFile(imageName, FileMode.Open, FileAccess.Read))
{
bimg.SetSource(stream);
}
}
return bimg;
}
// load the first image in recent images
BitmapImage first = GetImageFromIsolatedStorage(recent_images[0]);
// set the BitmapImage as the source of myImage to display it on the screen
this.myImage.Source = first;
只需逐行阅读他们的代码和我的代码。不跳过步骤也不会太难。