简体   繁体   English

Uint8ClampedArray 到 Uint8Array 到 base64

[英]Uint8ClampedArray to Uint8Array to base64

Is there a similar method of converting a Uint8ClampedArray to a regular array.是否有类似的方法将 Uint8ClampedArray 转换为常规数组。

var typedArray = new Uint8ClampedArray([1, 2, 3, 4]);
var normalArray = Array.prototype.slice.call(typedArray);

But then converting from Uint8ClampedArray to Uint8Array?但是然后从 Uint8ClampedArray 转换为 Uint8Array?

I understand there are differences in how values are assigned but is rather confusing to look into for me as the Uint8ClampedArray involves an image that is being drawn onto a canvas for which a downloadable blob link is made.我知道值的分配方式存在差异,但对我来说相当混乱,因为 Uint8ClampedArray 涉及一个被绘制到画布上的图像,该画布为其制作了可下载的 blob 链接。

My data looks like this:我的数据如下所示: 在此处输入图片说明

And then I try to convert it into base64 with this: https://gist.github.com/enepomnyaschih/72c423f727d395eeaa09697058238727然后我尝试将其转换为 base64: https : //gist.github.com/enepomnyaschih/72c423f727d395eeaa09697058238727

EDIT: Already tried putting it into the constructor of Uint8Array but when converting to base64 it does not appear to be valid.编辑:已经尝试将其放入 Uint8Array 的构造函数中,但是当转换为 base64 时,它似乎无效。

new Uint8Array(imageData.data)

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/Uint8Array#Syntax https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/Uint8Array#Syntax

我最终使用 canvas.toDataURL 而不是尝试自己转换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM