来自文件夹中图像列表的图像显示 C# UWP

我目前正在构建一个存储音乐并希望它显示用户可以上传的专辑图像的 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);

            }



        }



凤凰求蛊
浏览 167回答 2
2回答

三国纷争

你可以试试这段代码<Image&nbsp;Source="ms-appx:///Assets/logo.png"&nbsp;/>确保图像属性将“构建操作”设置为“内容”,将“复制到输出目录”设置为“始终复制”。

LEATH

newImage.ImageSource&nbsp;=&nbsp;...完整教程:https&nbsp;:&nbsp;//docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.controls.image.source
打开App,查看更多内容
随时随地看视频慕课网APP