用JavaScript将Canvas内容转化成图片的方法

http://www.webhek.com/convert-canvas-image/

一、使用JavaScript将图片拷贝进画布

// Converts image to canvas; returns new canvas element function convertImageToCanvas(image) {
var canvas = document.createElement("canvas"); canvas.width = image.width; canvas.height = image.height; canvas.getContext("2d").drawImage(image, 0, 0);

return canvas;

}

二、用JavaScript将画布保持成图片格式

// Converts canvas to an image function convertCanvasToImage(canvas) {
var image = new Image(); image.src = canvas.toDataURL("image/png"); return image; }

axiaoyue

继续阅读此作者的更多文章