繁体   English   中英

如何打开和拆分隔离存储(WP8)中的最新图像?

[英]How to open and split the most recent image from isolated storage (WP8)?

我目前正在开发一款可以执行以下任务的应用:

1-拍照并将其保存在:独立存储和照相馆中。

2然后将图片分成不同的部分加载到不同的页面中。

所以我按照本教程介绍如何捕获照片并保存:

http://msdn.microsoft.com/zh-CN/library/windows/apps/hh202956(v=vs.105).aspx

现在,我只能在另一页面上查看和拆分最新图像。

有解决方案或想法吗?

抱歉,我不清楚,我想要的是一种查看我的应用程序捕获的最新照片的方式

相机应用程序样本将照片保存到相机胶卷以及应用程序隔离存储中。 这是他们使用的代码段。

// 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 ,因此您要做的就是保留您使用的所有fileNameList<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;

只需逐行阅读他们的代码和我的代码。 如果您不跳过步骤,这并不太难。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM