Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8274511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:45:01+00:00 2026-06-08T07:45:01+00:00

I can easily create a BitmapImage from a resource JPG image file using the

  • 0

I can easily create a BitmapImage from a resource JPG image file using the following code…

Windows::Foundation::Uri^ uri = ref new Windows::Foundation::Uri(L"ms-appx:///Hippo.JPG");
Imaging::BitmapImage^ image = ref new Imaging::BitmapImage(uri);

But WritableBitmap does not take an Uri. I see a SetSource method, but that needs a IRandomaccessStream and not an Uri. And I have no clue how to create one from a JPG file. I searched the net over and over again, but could not find a straight forward answer. Any help would be greatly appreciated.

I want something like this…

Windows::UI::Xaml::Media::Imaging::WriteableBitmap image = ref new Windows::UI::Xaml::Media::Imaging::WriteableBitmap();
image->SetSource(somehowGetRandomAccessStreamFromUri);

But, how do I get the IRandomaccessStream instance from a uri? I started working on C++ Metro app only today, so might be wrong, but I find it to be overly complicated with too much of onion peeling.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T07:45:03+00:00Added an answer on June 8, 2026 at 7:45 am

    In C# you would do something like

    var storageFile = await Package.Current.InstalledLocation.GetFileAsync(relativePath.Replace('/', '\\'));
    var stream = await storageFile.OpenReadAsync();
    var wb = new WriteableBitmap(1, 1);
    wb.SetSource(stream);
    

    I think in C++/CX you would do something like this:

    #include <ppl.h>
    #include <ppltasks.h>
    
    ...
    
    Concurrency::task<Windows::Storage::StorageFile^> getFileTask
        (Package::Current->InstalledLocation->GetFileAsync(L"Assets\\MyImage.jpg"));
    
    auto getStreamTask = getFileTask.then(
        [] (Windows::Storage::StorageFile ^storageFile)
        {
            return storageFile->OpenReadAsync();
        });
    
    getStreamTask.then(
        [] (Windows::Storage::Streams::IRandomAccessStreamWithContentType^ stream)
        {
            auto wb = ref new Windows::UI::Xaml::Media::Imaging::WriteableBitmap(1, 1);
            wb->SetSource(stream);
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can easily create Liferay portlets and themes individually using the Liferay plugin SDK.
I am using Omniauth and Devise. Users using gmail or FB can easily create
Visual Studio can easily create a project template from an existing project by exporting
in C++, I can easily create a function pointer by taking the address of
From Eclipse I can easily run all the JUnit tests in my application. I
Using scons I can easily set my include paths: env.Append( CPPPATH=['foo'] ) This passes
I can easily create alerts and open make it open a form with the
I have created an OOP environment for WebGL so I can easily create all
Say I have a Stream that's rather expensive to compute. I can easily create
I've started to construct a builder so that I can easily create test data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.