将图像加载到WinRT中的图像UI项目中

时间:2012-12-18 15:59:47

标签: windows-8 windows-runtime

我正在尝试将图片加载到我的win8应用的图片UI项目中。但到目前为止,我无法在UI上显示所选图像。   有人可以告诉我这样做的正确方法吗?

            Windows.Storage.Pickers.FileOpenPicker OpenPicker = new Windows.Storage.Pickers.FileOpenPicker();
            OpenPicker.FileTypeFilter.Add(".jpg");
            OpenPicker.FileTypeFilter.Add(".bmp");
            Windows.Storage.StorageFile picture =  await OpenPicker.PickSingleFileAsync();


            imgPreview.Source = new Windows.UI.Xaml.Media.Imaging.BitmapImage(new Uri(picture.Path, UriKind.Absolute));

            imgPreview.Stretch = Stretch.Fill;
            imgPreview.Visibility = Windows.UI.Xaml.Visibility.Visible;

1 个答案:

答案 0 :(得分:1)

请参阅此here上的帖子。

它应该是这样的:

XAML:

<Image Margin="5" Source="{Binding BMImage}" Height="100"/>

C#:

BitmapImage bmImage;
public BitmapImage BMImage
{
    get
    {
        return bmImage;
    }
}

bmImage = new BitmapImage();

bmImage.UriSource = new Uri(new Uri(
     Windows.Storage.ApplicationData.Current.TemporaryFolder.Path + "\\" +
     Windows.Storage.ApplicationData.Current.TemporaryFolder.Name), 
     "favicon.scale-100.ico");