工作与文件选择器在windows phone 8.1中选择的图像
本文关键字:选择 图像 phone 文件 选择器 windows 工作 | 更新日期: 2023-09-27 18:12:36
我想在windows phone 8.1中使用文件选择器挑选的图像。我选择了一个图像使用以下代码
private async void gallery_Tapped(object sender, TappedRoutedEventArgs e)
{
FileOpenPicker openPicker = new FileOpenPicker();
openPicker.ViewMode = PickerViewMode.Thumbnail;
openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
openPicker.FileTypeFilter.Add(".jpg");
openPicker.FileTypeFilter.Add(".jpeg");
openPicker.FileTypeFilter.Add(".png");
// Launch file open picker and caller app is suspended and may be terminated if required
openPicker.PickSingleFileAndContinue();
}
public async void ContinueFileOpenPicker(FileOpenPickerContinuationEventArgs args)
{
if (args.Files.Count > 0)
{
StorageFile file=args.Files[0];
IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.SetSource(fileStream);
MyImage.Source=bitmapImage;
}
else
{
}
}
ContinueFileOpenPicker不执行我尝试了这个,但无法理解。这里有谁能一步一步地指导我,我该怎么做才能成功?由于
protected override void OnActivated(IActivatedEventArgs args)
{
var root = Window.Current.Content as Frame;
var mainPage = root.Content as MainPage;
if (mainPage != null && args is FileOpenPickerContinuationEventArgs)
{
mainPage.ContinueFileOpenPicker(args as FileOpenPickerContinuationEventArgs);
}
}
把这段代码放到app. example .cs中,它会工作的。