首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用FileOpenPicker窗口上传照片8.1

使用FileOpenPicker窗口上传照片8.1
EN

Stack Overflow用户
提问于 2013-12-02 10:30:37
回答 1查看 851关注 0票数 0

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

代码语言:javascript
复制
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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-12-02 11:17:52

new BitmapImage(Uri)将不使用任何路径。它只支持URI的协议httpms-appxms-appdata。你必须使用流。

代码语言:javascript
复制
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;
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20326045

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档