在运行时 c# (uwp) 上向资产添加图像
Add an image to assets on runtime c# (uwp)
我正在尝试添加图片功能。用户可以上传项目的图片,并将该图片添加到我的项目的资产中以供将来使用。
这是我的代码:
private async void PickAFileButton_ClickAsync(object sender, RoutedEventArgs e)
{
FileOpenPicker openPicker = new FileOpenPicker();
openPicker.ViewMode = PickerViewMode.Thumbnail;
openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
openPicker.FileTypeFilter.Add(".jpg");
openPicker.FileTypeFilter.Add(".jpeg");
openPicker.FileTypeFilter.Add(".png");
StorageFile file = await openPicker.PickSingleFileAsync();
if (file != null)
{
// Application now has read/write access to the picked file
String a = "ms-appx:///Assets/" + file.Name;
theItem.Source = new BitmapImage(new Uri(a));
}
else
{
theImage.Text = "Operation cancelled.";
}
}
如何将给定的图片添加到我的项目的资产文件夹中,以便我可以在旁边显示它,并将其用于其他用途?
如有任何帮助,我将不胜感激。
How do I Add the given picture to my project's assets folder
uwp项目的assets文件夹在运行时间模型中是只读的,我们无法在运行时间添加图片。我们建议使用 Local
文件夹替换 Assets
文件夹。
private async void PickAFileButton_ClickAsync(object sender, RoutedEventArgs e)
{
FileOpenPicker openPicker = new FileOpenPicker();
openPicker.ViewMode = PickerViewMode.Thumbnail;
openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
openPicker.FileTypeFilter.Add(".jpg");
openPicker.FileTypeFilter.Add(".jpeg");
openPicker.FileTypeFilter.Add(".png");
StorageFile file = await openPicker.PickSingleFileAsync();
if (file != null)
{ await file.CopyAsync( ApplicationData.Current.LocalFolder );
// Application now has read/write access to the picked file
String a = "ms-appdata:///local/" + file.Name;
theItem.Source = new BitmapImage(new Uri(a));
}
else
{
theImage.Text = "Operation cancelled.";
}
}
我正在尝试添加图片功能。用户可以上传项目的图片,并将该图片添加到我的项目的资产中以供将来使用。 这是我的代码:
private async void PickAFileButton_ClickAsync(object sender, RoutedEventArgs e)
{
FileOpenPicker openPicker = new FileOpenPicker();
openPicker.ViewMode = PickerViewMode.Thumbnail;
openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
openPicker.FileTypeFilter.Add(".jpg");
openPicker.FileTypeFilter.Add(".jpeg");
openPicker.FileTypeFilter.Add(".png");
StorageFile file = await openPicker.PickSingleFileAsync();
if (file != null)
{
// Application now has read/write access to the picked file
String a = "ms-appx:///Assets/" + file.Name;
theItem.Source = new BitmapImage(new Uri(a));
}
else
{
theImage.Text = "Operation cancelled.";
}
}
如何将给定的图片添加到我的项目的资产文件夹中,以便我可以在旁边显示它,并将其用于其他用途?
如有任何帮助,我将不胜感激。
How do I Add the given picture to my project's assets folder
uwp项目的assets文件夹在运行时间模型中是只读的,我们无法在运行时间添加图片。我们建议使用 Local
文件夹替换 Assets
文件夹。
private async void PickAFileButton_ClickAsync(object sender, RoutedEventArgs e)
{
FileOpenPicker openPicker = new FileOpenPicker();
openPicker.ViewMode = PickerViewMode.Thumbnail;
openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
openPicker.FileTypeFilter.Add(".jpg");
openPicker.FileTypeFilter.Add(".jpeg");
openPicker.FileTypeFilter.Add(".png");
StorageFile file = await openPicker.PickSingleFileAsync();
if (file != null)
{ await file.CopyAsync( ApplicationData.Current.LocalFolder );
// Application now has read/write access to the picked file
String a = "ms-appdata:///local/" + file.Name;
theItem.Source = new BitmapImage(new Uri(a));
}
else
{
theImage.Text = "Operation cancelled.";
}
}