gpt4 book ai didi

c# - 在 Windows Phone 8.1 中使用文件选择器选择的图像

转载 作者:行者123 更新时间:2023-11-30 20:48:21 24 4
gpt4 key购买 nike

我想在 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 未执行 我试过了 this但无法理解。这里有任何人可以逐步指导我我应该怎么做才能让它发挥作用。谢谢

最佳答案

 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.xaml.cs 中它会起作用..

关于c# - 在 Windows Phone 8.1 中使用文件选择器选择的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24721813/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com