使用FileOpenPicker windows8.1上传照片

时间:2013-12-02 10:30:38

标签: c# image microsoft-metro winrt-xaml windows-8.1

我正在尝试使用FileOpenPicker将照片上传到我的应用程序,当我编写以下代码时:

FileOpenPicker open = new FileOpenPicker();
open.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
open.ViewMode = PickerViewMode.Thumbnail;

// Filter to include a sample subset of file types
open.FileTypeFilter.Clear();
open.FileTypeFilter.Add(".bmp");
open.FileTypeFilter.Add(".png");
open.FileTypeFilter.Add(".jpeg");
open.FileTypeFilter.Add(".jpg");

// Open a stream for the selected file
StorageFile file = await open.PickSingleFileAsync();

// ImageSource im = (new Uri (file.Path));
ChildPic.Source = new BitmapImage(new Uri(file.Path));

它没有给我一个错误,但Image控件留空。

路径中有值:C:\ Users \ Pictures \ New folder(15).jpg

1 个答案:

答案 0 :(得分:2)

new BitmapImage(Uri)不适用于任何路径。它仅支持具有协议URIhttpms-appx的{​​{1}}。你必须使用流。

ms-appdata