2

I have a C++/CX component that can return an image as a stream (I could easily make it return an IBuffer, if that makes things easier). Currently, the component's return type is IRandomAccessStream and the actual stream is a InMemoryRandomAccessStream.

I want to use this stream as the source for an image in a HTML/JavaScript Windows 8 app. The problem is that I don't know how to shove this stream, or an array that I can create from it, into the image. I've tried a few things, but for example URL.createObjectURL deosn't take just an IRandomAccessStream, it requires an IRandomAccessStreamWithContentType. I've also tried to use a canvas and imagedata (http://www.w3schools.com/tags/canvas_createimagedata.asp).

My next step will probably be to try to wrap my stream in a IRandomAccessStreamWithContentType and see if I can make that work. Either in JavaScript or in my C++/CX control.

Any suggestions on how to go about this would be appreciated.

Thanks, Tomas

Tomas
  • 131
  • 1
  • 7

1 Answers1

0

I've done this in C# before not in C++, but the basics should be similar.

  1. Get the byte array from the stream
  2. Convert the byte array to Base64String (Convert.ToBase64String)
  3. Now you can use this string directly in the image tag:

<img src="data:image/png;base64,YOUR_STRING" />

Tarek Ayna
  • 340
  • 4
  • 10
  • Thanks, although I already managed to solve it by creating a RandomAccessStreamReference and then reading from it (as it returns the correct thing for use in URL.createObjectURL. – Tomas Jan 07 '13 at 23:39
  • 1
    @Tomas I am having the same problem. It seams u have solve it. Would you be so kind to share it with us? – Panagiotis Lefas Feb 28 '13 at 14:05