gpt4 book ai didi

c# - 如何将存储文件分配给 ByteArray?

转载 作者:行者123 更新时间:2023-12-02 14:06:13 27 4
gpt4 key购买 nike

如何将存储文件分配给 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);
}
}

关于c# - 如何将存储文件分配给 ByteArray?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34246976/

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