photoChooserTask在Windows Phone 8中保存并查看图像

时间:2014-03-13 10:28:08

标签: windows-phone-8

我使用photoChooserTask来选择图像

我有这个xaml

<Image Width="180" Height="180" Stretch="UniformToFill" Margin="10,10,0,0"  HorizontalAlignment="Left" Source="{Binding ImagePhoto}"></Image>

<Button HorizontalAlignment="Left" click="ButtonAddPhoto_EventClick" content"select image">

在cs文件中

 public void ButtonAddPhoto_EventClick()
        {

             _PhotoChooserTask = new PhotoChooserTask();
             _PhotoChooserTask.Completed += new EventHandler<PhotoResult>(photoChooserTask_Completed);
             _PhotoChooserTask.Show();

        }

async void photoChooserTask_Completed(object sender, PhotoResult e)
        {
            if (e.TaskResult == Microsoft.Phone.Tasks.TaskResult.OK)
            {

                string FileName = Path.GetFileName(e.OriginalFileName);

                StorageFolder tmpfolder = await ApplicationData.Current.LocalFolder.GetFolderAsync("temp");
                StorageFile file = await tmpfolder.CreateFileAsync(_PhotoFileName, CreationCollisionOption.ReplaceExisting);
                using (Stream current = await file.OpenStreamForWriteAsync())
                {
                    await e.ChosenPhoto.CopyToAsync(current);
                }

                ImagePhoto = new Uri("isostore:/temp/" + FileName, UriKind.Absolute);

            }
        }

图像保存到Isolatedstorage但不在图像中查看。为什么? 谢谢

1 个答案:

答案 0 :(得分:0)

您可以使用Stream来读取刚刚保存的图像,然后将图像的来源设置为此流。并在你的xaml中绑定图像...

修改

 
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;
    }