You can use the GetPointerToPixelData function from Obtaining pointers to data buffers (C++/CX)
with a WriteableBitmap that you can set as source of an Image
How to load an image from a base64 encoded png in UWP app C++/CX

KGabesz
1
Reputation point
Hello!
I have a base64 encoded PNG file (a QR code), and I would like to show the picture on a Page.
I have this XAML element:
<Image Grid.Row="3" Name="QRCode" Height="200" Width="200"/>
I converted the base64 string to an IBuffer:
Windows::Storage::Streams::IBuffer^ buf = Windows::Security::Cryptography::CryptographicBuffer::DecodeFromBase64String(base64string);
Now I would like to create a BitmapImage, to set it as the source of the Image on the page:
BitmapImage^ Image = ref new BitmapImage();
QRCode->Source = Image;
The question is, that how can I set the IBuffer as the source of the Image? What is the missing step?
Thanks if you help me!
2 answers
Sort by: Most helpful
-
Castorix31 71,621 Reputation points
2022-11-02T09:03:43.527+00:00 -
KGabesz 1 Reputation point
2022-11-02T13:19:45.503+00:00 Meanwhile I found a working solution, so I paste it here, to help others who are facing with the same problem:
Windows::Storage::Streams::IBuffer^ buf = Windows::Security::Cryptography::CryptographicBuffer::DecodeFromBase64String(base64string); auto bitmapImage = ref new BitmapImage(); QRCode->Source = bitmapImage; auto stream = ref new InMemoryRandomAccessStream(); auto writer = ref new DataWriter(stream->GetOutputStreamAt(0)); writer->WriteBuffer(buf); create_task(writer->StoreAsync()).then([=](unsigned bytesStored) { return bitmapImage->SetSourceAsync(stream); });