canvas.toDataURL(type, args)

canvas.toDataURL(type, args)
该方法能够将canvas转换为图像,图像是基于Base64编码的。如果不指定两个参数,无参数调用该方法,转换的图像格式为png格式

•type:指定要转换的图像格式,如 image/png、image/jpeg等。
•args:可选参数。例如,如果type为image/jpeg,则args可以是0.0和1.0之间的值,以指定图像的品质。

例如,下面的代码将canvas中已绘制的内容在一个新的浏览器窗口或选项卡中打开:

var canvas = document.getElementById("myCanvas");
window.open(canvas.toDataURL("image/png"));

其他资料地址:

https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toDataURL

posted @ 2016-01-04 18:07  天马3798  阅读(2502)  评论(0编辑  收藏  举报