2012-12-18 75 views
0

我試圖將圖像加載到我的win8應用程序的圖像UI項目中。但到目前爲止,我無法將所選圖像顯示在用戶界面上。 有人可以告訴我如何正確的做法嗎?將圖像加載到WinRT中的圖像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

看到我的文章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");