如何将存储文件分配给 ByteArray?
var file = await openPicker.PickSingleFileAsync();
如何将存储文件分配给 ByteArray?
var file = await openPicker.PickSingleFileAsync();
这是一个使用文件选择器的示例,获取存储文件并将其转换为字节数组。
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);
}
}