当我编写以下代码时,我试图使用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));它没有给我一个错误,但是图像控件是空白的。
路径中有值: C:\Users\Pictures\New文件夹(15).jpg
发布于 2013-12-02 11:17:52
new BitmapImage(Uri)将不使用任何路径。它只支持URI的协议http,ms-appx,ms-appdata。你必须使用流。
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));
var bmp = new BitmapImage();
using (var strm = await file.OpenReadAsync())
{
bmp.SetSource(strm);
ChildPic.Source = bmp;
}https://stackoverflow.com/questions/20326045
复制相似问题