canvas保存文件
js:
function draw(id){
// 获取canvas的id
var canvas = document.getElementById('canvas');
// 取得上下文
var context = canvas.getContext('2d');
// 绘制背景
context.fillStyle = "#f45da9";
context.fillRect(0,0,500,350);
...
//保存文件
window.location = canvas.toDataURL('image/jpeg');//会输出一个jpeg的图片
}
解析:
canvas.toDataURL(type);表示输出的MIME类型。
什么是MIME类型? jpg、image/jpeg。