0

在我的Windows應用程序中,我試圖從本地機器加載圖像到服務器,但在StorageFile file = await open.PickSingleFileAsync();語句上面臨System.Runtime.InteropServices.COMException的異常。方法如下:在Windows應用程序中收到「System.Runtime.InteropServices.COMException」

FileOpenPicker open = new FileOpenPicker(); 
StorageFile file = await open.PickSingleFileAsync(); 
if (file != null) 
{ 
    using (IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read)) 
    { 
     // Set the image source to the selected bitmap 
     BitmapImage bitmapImage = new BitmapImage(); 
     bitmapImage.DecodePixelWidth = 600; //match the target Image.Width, not shown 
     await bitmapImage.SetSourceAsync(fileStream); 
     big_image.Source = bitmapImage; 
    } 
} 

如何解決?我正在使用VS '13。 Big_image是在xaml中定義的圖像,我試圖設置其來源。

回答

1

我加入一些新的東西得到了解決:

FileOpenPicker openPicker = new FileOpenPicker(); 
openPicker.ViewMode = PickerViewMode.Thumbnail; 
openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary; 
openPicker.FileTypeFilter.Add(".jpg"); 
openPicker.FileTypeFilter.Add(".jpeg"); 
openPicker.FileTypeFilter.Add(".png"); 

StorageFile file = await openPicker.PickSingleFileAsync(); 
if (file != null) 
    { 
     using (IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read)) 
     { 
      // Set the image source to the selected bitmap 
      BitmapImage bitmapImage = new BitmapImage(); 
      await bitmapImage.SetSourceAsync(fileStream); 
      big_image.Source = bitmapImage; 
     } 
    } 
相關問題