locked
Loading an image file in WinRT

    Question

  • I have a WinRT project, and am getting an error when trying to preview an image.  I have set capabilities to allow access to the Pictures library, and am using the following code:

         var file = await Windows.Storage.KnownFolders.PicturesLibrary.GetFileAsync(path);
         var fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
         var img = new BitmapImage();
         img.SetSource(fileStream);

    This error occurs on the first line:

        A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll

        Additional information: Error HRESULT E_FAIL has been returned from a call to a COM component.

    I've tried other operations, such as `folder.GetFilesAsync()` with the same error.  Is there another or capability that I need to allow this functionality to work correctly?
    Monday, June 02, 2014 7:11 AM

All replies

  • did you enable access to the PictureFolder in your manifest?

    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    Monday, June 02, 2014 7:47 AM
  • Yes, sorry, that was what I meant when I said "allow access"
    Monday, June 02, 2014 7:50 AM
  • Hi pcmichaels,

    Problem solved? The code you are using actually works fine on my side, could you try it with another machine? I'm afraid this could be your environment issue.

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Wednesday, June 18, 2014 7:25 AM
    Moderator
  • No - it still occurs; I will try it on another PC, but surely if it can occur on my machine it could occur on a machine running it, if they have their 'environment' incorrectly configured.
    Wednesday, June 18, 2014 12:30 PM
  • Alright, give a try and let's see if the same thing happen.


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Friday, June 20, 2014 2:07 AM
    Moderator