winrt,javascript,来自字节数组的图像 [英] winrt, javascript, image from byte array

查看:136
本文介绍了winrt,javascript,来自字节数组的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C ++ / CX组件可以将图像作为流返回(如果这样可以让事情变得更容易,我可以很容易地让它返回IBuffer)。目前,组件的返回类型是IRandomAccessStream,实际的流是InMemoryRandomAccessStream。

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.

我想将此流用作HTML / JavaScript Windows 8中图像的源应用程序。问题是我不知道如何将这个流或我可以从中创建的数组推送到图像中。我已经尝试过一些东西,但是例如URL.createObjectURL deos不仅仅需要一个IRandomAccessStream,它需要一个IRandomAccessStreamWithContentType。我也试过使用画布和图像数据(http://www.w3schools.com/tags/canvas_createimagedata.asp)。

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).

我的下一步可能是尝试将我的流包装在IRandomAccessStreamWithContentType中,看看我是否可以使其工作。无论是在JavaScript中还是在我的C ++ / CX控件中。

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.

谢谢,
Tomas

Thanks, Tomas

推荐答案

我之前在C#中做过这个,而不是在C ++中,但基础知识应该是类似的。

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


  1. 从流中获取字节数组

  2. 将字节数组转换为Base64String(转换。 ToBase64String

  3. 现在您可以直接在图片标签中使用此字符串:

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

这篇关于winrt,javascript,来自字节数组的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆