0

I have searched the forums and came across this Getting an array of bytes out of Windows::Storage::Streams::IBuffer but I wasn't able to get anything out of it. It may be a bit too convuluted for me to figure out.

The crux of my problem is that I have an IBuffer from calling RenderTargetBitmap->GetPixelsAsync(). I now need to create a CanvasBitmap from this data by using the function provided here http://microsoft.github.io/Win2D/html/M_Microsoft_Graphics_Canvas_CanvasBitmap_CreateFromBytes.htm

I have found no way of getting the data from the IBuffer to an array that will work. I found a way to get the data into a vector

//convert IBuffer to byte array
auto reader = ::Windows::Storage::Streams::DataReader::FromBuffer(buf);

std::vector<unsigned char> data(reader->UnconsumedBufferLength);

if (!data.empty())
    reader->ReadBytes(
        ::Platform::ArrayReference<unsigned char>(
            &data[0], data.size()));

But from this point on, I have found no way to get this into an array. I have attempted to use all the ideas from How to convert vector to array in C++ to no avail. Any help would be greatly appreciated

Community
  • 1
  • 1
Zori
  • 1
  • 1
  • `&data[0]` *is* your array. Nothing to convert. – n. m. could be an AI Dec 18 '15 at 06:37
  • You don't put any data into your vector - all you do is creating a vector with length `reader->UnconsumedBufferLength` whose elements are set to 0 – MikeMB Dec 18 '15 at 06:51
  • @MikeMB WOW! I had no idea that's what was happening. I pulled it directly from another one of the posts on here. Thank you! I will use this information to move forward – Zori Dec 18 '15 at 07:00

0 Answers0