admin管理员组文章数量:1327335
I need to transfer webcam data over the internet from one browser to another.
The webcam is displayed in a HTML5 canvas
. Then I get its dataUrl, and turn it into a blob
. Then I send this blob to my server.
From what I understand, the blob is essentially a byte array
. I've converted it to a byte array on the server-side, it has the same length as blob.size
in the browser, so that seems fine. I need to add a sender id to it, so I convert an integer to an array of 4 bytes
and add it to the front of the byte array.
Now I need to send this modified blob to the other browser. And this is where I'm confused.
- How do I read out the first 4 bytes in javascript and turn it into an integer again?
- And how do I cut off the rest of the blob?
I need to transfer webcam data over the internet from one browser to another.
The webcam is displayed in a HTML5 canvas
. Then I get its dataUrl, and turn it into a blob
. Then I send this blob to my server.
From what I understand, the blob is essentially a byte array
. I've converted it to a byte array on the server-side, it has the same length as blob.size
in the browser, so that seems fine. I need to add a sender id to it, so I convert an integer to an array of 4 bytes
and add it to the front of the byte array.
Now I need to send this modified blob to the other browser. And this is where I'm confused.
- How do I read out the first 4 bytes in javascript and turn it into an integer again?
- And how do I cut off the rest of the blob?
-
1
use the
parseInt(someInt, base);
for turning 4bytes into an integer – Callum Linington Commented Apr 17, 2014 at 17:51
1 Answer
Reset to default 7You can use Blob.slice() method to get bytes.
See docs: https://developer.mozilla/en-US/docs/Web/API/Blob.slice
1)
var bytes = blob.slice(0,4);
2)
var arrayOfBytes = [];
for(var i=0;i<blob.size/4;i++){
arrayOfBytes[i] = blob.slice(i*4,4+(i*4));
}
Note: I didn't test it!
本文标签:
版权声明:本文标题:html - How do I read out the first 4 bytes in javascript, turn it into an integer and remove the rest? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742198791a2431572.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论