我试图将图像或文件从计算机复制到UWP Application的本地文件夹中,但尚未完成。我总是告诉文件访问被拒绝。我在Microsoft网站上搜索了google和UWP资源,并使用了从这些链接中获得的大多数方法。但是我还没有。
太谢谢你了 我找到了解决方案,您的回答很有用。
这是解决方案
这是上传按钮图片
private async void BtnAddImage_OnClick(object sender, RoutedEventArgs e)
{
var imagePicker = new FileOpenPicker
{
ViewMode = PickerViewMode.Thumbnail,
SuggestedStartLocation = PickerLocationId.Desktop,
FileTypeFilter = { ".jpg", ".png", ".bmp", ".gif", ".tif" }
};
var imageFile = await imagePicker.PickSingleFileAsync();
if (imageFile == null)
{
return;
}
_storageFile = imageFile;
_path = imageFile.Path;
var dataPackage = new DataPackage();
dataPackage.SetBitmap(RandomAccessStreamReference.CreateFromFile(imageFile));
Clipboard.SetContent(dataPackage);
var dataPackageView = Clipboard.GetContent();
if (!dataPackageView.Contains(StandardDataFormats.Bitmap)) return;
IRandomAccessStreamReference imageReceived = await dataPackageView.GetBitmapAsync();
if (imageReceived == null) return;
using (var imageStream = await imageReceived.OpenReadAsync())
{
var bitmapImage = new BitmapImage();
bitmapImage.SetSource(imageStream);
ImgSupplier.Source = bitmapImage;
}
StorageApplicationPermissions.FutureAccessList.Add(imageFile);
}
重新运行路径
private static string GetPath(string folderName)
{
var root = Windows.ApplicationModel.Package.Current.InstalledLocation.Path + @"\Assets\";
var fullPath = Path.Combine(root, folderName);
return fullPath;
}
这是一个保存按钮
private StorageFile _storageFile;
private async void BtnAddExpenditure_OnClick(object sender, RoutedEventArgs e)
{
var getPath = GetPath("Companies");
var folder = await StorageFolder.GetFolderFromPathAsync(getPath);
await _storageFile.CopyAsync(folder, Guid.NewGuid() + "." + _storageFile.FileType);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句