我正在使用节点js,express和javascript。我正在客户端用画布画一幅画。我想将该图像发送给其他用户。但到目前为止,当我将其发送到服务器并且服务器将其发送到该特定客户端时,我得到了一个损坏的图像图标。我该怎么做?我必须采取另一种方法吗?我转换文件了吗?如有任何帮助,我愿意回答任何进一步的问题,提前致谢!
CLIENT.JS
<img id="canvasimg" style="display:none;">
<img id="canvasimgSENTBYSERVER" style="display:none;">
var canvas = document.getElementById('canvas');
var context = canvas.getContext('2d');
//create a drawing blah blah blah
function sendDrawing()
{
document.getElementById("canvasimg").style.border = "2px solid";
var dataURL = canvas.toDataURL();
document.getElementById("canvasimg").src = dataURL;
socket.emit('image', dataURL);
}
socket.on('send image to client', function(dataURL1)
{
document.getElementById("canvasimgSENTBYSERVER").src = dataURL1;
document.getElementById("canvasimgSENTBYSERVER").style.display = "inline";
console.log("drawn image test");
$canvasimg.show();
$canvasimgSENTBYSERVER.show();
});
SERVER.js
socket.on('image', function (dataUrl)
{
user1.emit('send image to client',{user:users[users.indexOf(socket.username)],dataUrl});
});