none
How to create a BitmapImage from std::string of png data in UWP using C++/CX RRS feed

  • Question

  • I want to create a BitmapImage from std::string of png binary data using C++/CX. BitmapImage is getting created but when binded with the Image element's source in Xaml it is not getting displayed. Here is my code.

    void setImage(std::string imageDataStr, uint64_t len) {
    
        auto stream = ref new InMemoryRandomAccessStream();
        auto writer = ref new DataWriter(stream->GetOutputStreamAt(0));
    
        Platform::Array<unsigned char>^ data = ref new Platform::Array<unsigned char>((unsigned char*)imageDataStr.data(), len);
        writer->WriteBytes(data);
    
        create_task(writer->StoreAsync()).then([=](unsigned bytesStored)
        {
            Image->SetSource(stream);
        });
    }

    Am i doing anything wrong?

    Any suggestions on how to do it.

    Tuesday, October 31, 2017 5:11 AM

All replies

  • Hi Bharadwaj Komirishetty

    Have you checked that the byte array is correct? Please ensure the byte array used to create the bitmapimage is correct. I suggest that you could save the bite array to local folder as a PNG file. If the PNG file isn’t correct, it means there are something wrong when you convert the string data to the Byte array.

    If the PNG file is correct, the problem could be related to how you bind the bitmapimage with the Image element. In that case, you might need to show me the codes how you set binding to the Image element.

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.



    Wednesday, November 1, 2017 11:15 AM
    Moderator