1) FileOpenPicker オブジェクトを使って、目的のファイルに対応する StorageFile オブジェクトを作成
2) StorageFile オブジェクトの OpenAsync メソッドで目的のファイルに対するストリーム(random-access stream)を取得
3) BitmapImage オブジェクトの SetSource メソッドでストリームを渡す
4) BitmapImage そのものを、Image コントロールの Source プロパティにセット
private async Task DisplayImageFileAsync(StorageFile file)
{
// Request persisted access permissions to the file the user selected.
// This allows the app to directly load the file in the future without relying on a
// broker such as the file picker.
m_fileToken = m_futureAccess.Add(file);
// Display the image in the UI.
BitmapImage src = new BitmapImage();
src.SetSource(await file.OpenAsync(FileAccessMode.Read));
Image1.Source = src;
AutomationProperties.SetName(Image1, file.Name);
// Use BitmapDecoder to attempt to read EXIF orientation and image dimensions.
await GetImageInformationAsync(file);
ExifOrientationTextblock.Text = Helpers.GetOrientationString(m_exifOrientation);
UpdateImageDimensionsUI();
ScaleSlider.IsEnabled = true;
RotateLeftButton.IsEnabled = true;
RotateRightButton.IsEnabled = true;
SaveButton.IsEnabled = true;
SaveAsButton.IsEnabled = true;
CloseButton.IsEnabled = true;
}
▲ Microsoft の実際のサンプルコード
FileAccessMode enumeration