摘自: http://segmentfault.com/q/1010000000202581
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
// 将图片变成 DataURI var img = new Image(); img.onload = function() { var canvas = document.createElement('canvas'); canvas.width = img.width; canvas.height = img.height; var ctx = canvas.getContext('2d'); ctx.drawImage(imageObj); // 这里就是你要的 DataURI var DataURI = canvas.toDataURL(); // 保存下来 chrome.storage.local.set({image : DataURI}); } img.src = 'http://xxxx'; // 这里写你的图片 url |