我目前正在构建一个存储音乐并希望它显示用户可以上传的专辑图像的 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=0x409
namespace 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);
}
}
三国纷争
LEATH
相关分类