这是一个如何实现您所需要的示例:
1) 画点东西
<canvas id="myCanvas" width="578" height="200"></canvas><script> var canvas = document.getElementById('myCanvas'); var context = canvas.getContext('2d'); // begin custom shape context.beginPath(); context.moveTo(170, 80); context.bezierCurveTo(130, 100, 130, 150, 230, 150); context.bezierCurveTo(250, 180, 320, 180, 340, 150); context.bezierCurveTo(420, 150, 420, 120, 390, 100); context.bezierCurveTo(430, 40, 370, 30, 340, 50); context.bezierCurveTo(320, 5, 250, 20, 250, 50); context.bezierCurveTo(200, 5, 150, 20, 170, 80); // complete custom shape context.closePath(); context.lineWidth = 5; context.fillStyle = '#8ED6FF'; context.fill(); context.strokeStyle = 'blue'; context.stroke();</script>
2) 将画布图像转换为URL格式(base64)
var dataURL = canvas.toDataURL();
3) 通过Ajax将其发送到您的服务器
$.ajax({ type: "POST", url: "script.php", data: { imgbase64: dataURL }}).done(function(o) { console.log('saved'); // If you want the file to be visible in the browser // - please modify the callback in javascript. All you // need is to return the url to the file, you just saved // and than put the image in your browser.});
3) 将base64作为图像保存在服务器上
这是在PHP中执行此 *** 作的方法,每种语言都具有相同的想法:
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)