这里是一个使用文件选择器的示例,获取一个存储文件并将其转换为字节数组。
private async void Button_Click_2(object sender, RoutedEventArgs e) { var picker = new FileOpenPicker(); picker.ViewMode = PickerViewMode.Thumbnail; picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary; picker.FileTypeFilter.Add(".jpeg"); picker.FileTypeFilter.Add(".jpg"); picker.FileTypeFilter.Add(".png"); var file = await picker.PickSingleFileAsync(); if (file != null) { var stream = await file.OpenStreamForReadAsync(); var bytes = new byte[(int)stream.Length]; stream.Read(bytes, 0, (int)stream.Length); } }