将IMG转换为字节 [英] Convert IMG to bytes

查看:152
本文介绍了将IMG转换为字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个将拍摄图像并将其字节转换为数组的游戏,例如3x3 img将返回9个字节。我想在Java Script中这样做,所以我可以得到img。如果你能帮助我,我真的很感激。谢谢



我尝试了什么:



我已经尝试了很多在互联网上的东西,我无法找到如何使用它:/

解决方案

这不起作用?

[ ^ ]



var img = new Image();

img.src ='image.jpg';

var context = document.getElementById('canvas')。getContext('2d ');

context.drawImage(img,0,0);

data = context.getImageData(x,y,1,1).data;

请参考以下链接:



如何使用javascript将图像转换为字节数组? - 堆栈溢出 [ ^ ]


I am trying to make a game that will take a image and get its bytes into an array, such as a 3x3 img will return 9 bytes. I want to do this in Java Script so I can get the img. I really would appreciated it if you would help me. Thanks

What I have tried:

I have tried a lot of stuff on the internet and I couldn't find out how to use it :/

解决方案

this doesn't work?
[^]

var img = new Image();
img.src = 'image.jpg';
var context = document.getElementById('canvas').getContext('2d');
context.drawImage(img, 0, 0);
data = context.getImageData(x, y, 1, 1).data;


Please refer following link :

How to convert image to byte array using javascript ? - Stack Overflow[^]


这篇关于将IMG转换为字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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