一、代码:
private async void BtnPickAndShow_Clicked(object sender, EventArgs e)
{
try
{
var result = await FilePicker.PickAsync(PickOptions.Default);
if (result != null)
{
txt1.Text = $"文件名: {result.FileName}";
if (result.FileName.EndsWith("jpg", StringComparison.OrdinalIgnoreCase) ||
result.FileName.EndsWith("png", StringComparison.OrdinalIgnoreCase))
{
var stream = await result.OpenReadAsync();
imgPickAndShow.Source = ImageSource.FromStream(() => stream);
}
}
}
catch (Exception ex)
{
// 用户取消或出现问题
await DisplayAlert("用户取消或出现问题", ex.Message, "关闭");
}
}
标签:stream,await,FilePicker,FileName,选择,EndsWith,result,MAUI
From: https://www.cnblogs.com/qq2806933146xiaobai/p/17009997.html