收到“System.Runtime.InteropServices.COMException"在Windows

本文关键字:quot Windows COMException System Runtime InteropServices 收到 | 更新日期: 2023-09-27 17:54:22

在我的windows应用程序中,我试图从本地机器加载图像到服务器,但在语句StorageFile file = await open.PickSingleFileAsync();上面临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中定义的图像,我正在尝试设置其来源。

收到“System.Runtime.InteropServices.COMException"在Windows

我通过添加一些新东西得到了解决方案:

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;
      }
   }

microsoft.phone.tasks。Photochoosertask是用来挑选图片的