是否可以在 JavaScript 中查看图像文件的原始数据?
我正在尝试编写一个将图像转换为其十六进制转储的脚本。
如何查看正在写入图像文件的数据?
您可以使用 XHR 执行此操作:
var xhr = new XMLHttpRequest();
xhr.open('GET', '/my/image/file.png', true);
xhr.responseType = 'arraybuffer'; // this will accept the response as an ArrayBuffer
xhr.onload = function(buffer) {
var words = new Uint32Array(buffer),
hex = '';
for (var i = 0; i < words.length; i++) {
hex += words.get(i).toString(16); // this will convert it to a 4byte hex string
}
console.log(hex);
};
xhr.send();
查看文档数组缓冲区s and 类型数组s
你可以看到我如何在测试中使用它here
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)