IInputStream to IRandomAccessStream RRS feed

  • Question

  • Hello,

    I'm using the Background Transfer service to download an image file. I'd like to load the image into a XAML Image control, however the Background Transfer service returns the downloaded data in a a stream of type IInputStream. I'm trying to load this data into the BitmapImage class, however BitmapImage.SetSource() takes in a stream of type IRandomAccessStream.

    How would I convert a stream of type IInputStream to IRandomAccess stream?



    Saturday, November 5, 2011 10:09 PM


  • Hi,

    Do you know where you are saving this file?  if yes, then you have a StorageFile^ corresponding to this file.  In that case, you can create a IRandomAccessStream for this file and associate with the image element in the following way:

    		auto file = op->GetResults();
    		auto openOp = file->OpenAsync(FileAccessMode::Read);
    		openOp->Completed = ref new AsyncOperationCompletedHandler<Streams::IRandomAccessStream^>([file, this](IAsyncOperation<Streams::IRandomAccessStream^> ^stop)
    			auto strm = stop->GetResults();
    			CapturedVideo->SetSource(strm, file->FileType);


    Raman Sharma | Program Manager, Visual C++ | @rasharm_msft

    (if my post has answered your question, please consider using the 'mark as answer' feature in the forums to help others)
    • Proposed as answer by Raman Sharma Sunday, November 6, 2011 4:31 AM
    • Marked as answer by Jie Bao Wednesday, December 7, 2011 9:40 AM
    Sunday, November 6, 2011 4:31 AM