WinJS,从字节数组中显示图像? [英] WinJS, display image from a byte array?

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

问题描述

我正在寻找一种显示存储在字节数组中的JPEG图像的方法。这是一个用Javascript构建的Windows 8商店应用程序。字节数组从C#WinRT组件返回。它在C#中的类型是 byte []

I'm looking for a way to display a JPEG image stored in a byte array. This is a Windows 8 Store App built in Javascript. The byte array is returned from a C# WinRT component. Its type in C# is byte[].

基本上,我想要的是获取一个对象以便我可以调用:

Basically, what I want is to get an object so that I can call:

URL.createObjectURL(bytearray, {oneTimeOnly: true});

。目前这会产生运行时错误,因为不支持数组接口。

upon. Currently this generates a runtime error because the array interface is not supported.

提前致谢。

推荐答案

我发现了一种更容易的方法。

I discovered a far easier method.

var blob = new Blob([bytes], {type: "image/jpg"});
var url = URL.createObjectURL(blob, { oneTimeOnly: true });

Blob 实际上直接由<$支持C $ C> URL.createObjectURL 。唯一的问题是你必须指定一个mime格式来识别缓冲区格式,在我的情况下是可能的。

Blob is actually supported directly by URL.createObjectURL. The only catch is that you have to specify a mime format to identify the buffer format, which in my case is possible.

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

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