我目前正在构建一个存储音乐并希望它显示用户可以上传的专辑图像的 UWP 应用程序。我已经想出了如何将图像保存到文件中,但是即使在尝试将它们绑定到 XAML 中的图像控件之后,也无法显示它们。我对此很陌生,所以如果这是一个简单的解决方法,我深表歉意。这是我的 MainPage.xaml.cs 中的代码:using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Runtime.InteropServices.WindowsRuntime;using System.Text;using Windows.Foundation;using Windows.Foundation.Collections;using Windows.Media.Core;using Windows.Storage;using Windows.Storage.FileProperties;using Windows.UI.Xaml;using Windows.UI.Xaml.Controls;using Windows.UI.Xaml.Controls.Primitives;using Windows.UI.Xaml.Data;using Windows.UI.Xaml.Input;using Windows.UI.Xaml.Media;using Windows.UI.Xaml.Media.Imaging;using Windows.UI.Xaml.Navigation;// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409namespace MyMusicLibrary{ /// <summary> /// An empty page that can be used on its own or navigated to within a Frame. /// </summary> public sealed partial class MainPage : Page { public MainPage() { this.InitializeComponent(); }private async void ImageButton_Click(object sender, RoutedEventArgs e) { var picker = new Windows.Storage.Pickers.FileOpenPicker(); picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail; picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary; picker.FileTypeFilter.Add(".jpg"); picker.FileTypeFilter.Add(".jpeg"); picker.FileTypeFilter.Add(".png"); var image = await picker.PickSingleFileAsync(); var folder = ApplicationData.Current.LocalFolder; var imageFolder = await folder.CreateFolderAsync("imagefolder", CreationCollisionOption.OpenIfExists); if (imageFolder != null && image != null) { var newImage = await image.CopyAsync(imageFolder, image.Name, NameCollisionOption.GenerateUniqueName); } }
2 回答
三国纷争
TA贡献1804条经验 获得超7个赞
你可以试试这段代码
<Image Source="ms-appx:///Assets/logo.png" />
确保图像属性将“构建操作”设置为“内容”,将“复制到输出目录”设置为“始终复制”。
LEATH
TA贡献1936条经验 获得超6个赞
newImage.ImageSource = ...
完整教程:https : //docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.controls.image.source
- 2 回答
- 0 关注
- 166 浏览
添加回答
举报
0/150
提交
取消