我正在开发一个应用程序,我在其中接收存储在 uint8Array 中的图像数据。然后我将此数据转换为 Blob,然后构建图像 url。
从服务器获取数据的简化代码:
var array;
var req = new XMLHttpRequest();
var url = "img/" + uuid + "_" +segmentNumber+".jpg";
req.open("GET", url, true);
req.responseType = "arraybuffer";
req.onload = function(oEvent) {
var data = req.response;
array = new Int8Array(data);
};
构造函数:
out = new Blob([data], {type : datatype} );
Blob 构造函数引起了问题。它适用于除移动设备和桌面设备上的 Chrome 之外的所有浏览器。
使用 Blob:
// Receive Uint8Array using AJAX here
// array = ...
// Create BLOB
var jpeg = new Blob( [array.buffer], {type : "image/jpeg"});
var url = DOMURL.createObjectURL(jpeg);
img.src = url;
桌面 Chrome给我一个警告:ArrayBuffer values are deprecated in Blob Constructor. Use ArrayBufferView instead.
移动 Chrome给我一个错误:illegal constructor
如果我将构造函数更改为在 Chrome 上工作,它在其他浏览器上会失败。