winrt, javascript, image from byte array

岁酱吖の 提交于 2019-12-11 01:25:13

问题


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


回答1:


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" />



来源:https://stackoverflow.com/questions/14162945/winrt-javascript-image-from-byte-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!