我使用node.js將畫布保存爲圖像 img in writeFile通過在我的畫布元素上使用toDataURL進行提取。 它doenot保存文件 這裏是我的代碼如何將畫布數據保存到文件
var fs = IMPORTS.require('fs');
var path = IMPORTS.require('path');
path.exists('images/', function(exists){
if (exists) {
fs.writeFile('images/icon.png', img, function(err){
if (err)
callback({
error: false,
reply: err
});
console.log('Resized and saved in');
callback({
error: false,
reply: 'success.'
});
});
}
else {
callback({
error: true,
reply: 'File did not exist.'
});
}
});
您可以包含您的畫布代碼或您正在測試的網址,以便我們可以運行代碼而無需編寫任何樣板文件? (見http://sscce.org/)如果您希望人們提供幫助,您可能還想詳細說明您的描述。 – timoxley 2011-05-03 14:41:26