【发布时间】:2014-01-23 16:43:43
【问题描述】:
我想使用 c# 和 xaml 在图片库中的应用(MediaElement)中显示图片
这是我的代码:
media.PosterSource = new BitmapImage(new Uri("file//C:/Users/Siio/Pictures/bird.jpg", UriKind.Absolute));
但图像不会出现。
有什么建议吗?
更新 C#
StorageFolder photoFolder = KnownFolders.PicturesLibrary;
List<string> photoTypeFilter = new List<string>();
photoTypeFilter.Add(".png");
QueryOptions queryOption = new QueryOptions(CommonFileQuery.OrderByName, fileTypeFilter);
StorageFileQueryResult queryResults = photoFolder.CreateFileQueryWithOptions(queryOptions);
IReadOnlyList<StorageFile> filess = await queryResult.GetFilesAsync();
foreach (StorageFile fil in filess)
{
MusicProperties musicProperty = await fil.Properties.GetMusicPropertiesAsync();
if (musicProperty.Title == UpdateFav.F_Title)
{
Uri uri = new Uri(@"C:\Users\Christopher\Pictures\" + UpdateFav.F_Title + ".png");
Uri uri1 = new Uri(uri.AbsoluteUri);
BitmapImage im = new BitmapImage(uri1);
media.PosterSource = im;
}
}
XAML:
<MediaElement x:Name="media" HorizontalAlignment="Left" Height="398" Margin="122,63,0,0" Grid.Row="1" VerticalAlignment="Top" Width="592" AudioCategory="BackgroundCapableMedia" PosterSource="Assets/BG2.jpg" MediaOpened="media_MediaOpened"/>
【问题讨论】:
标签: c# image path mediaelement