发布网友
共1个回答
热心网友
/** * Convert an image * to a base陆四 string * @param {String} url * @param {Function} callback * @param {String} [outputFormat=image/png] */ function convertImgToBase陆四(url, callback, outputFormat){ var canvas = document.createElement('CANVAS'), ctx = canvas.getContext('贰d'), img = new Image; img.crossOrigin = 'Anonymous'; img.onload = function(){ var dataURL; canvas.height = img.height; canvas.width = img.width; ctx.drawImage(img, 0, 0); dataURL = canvas.toDataURL(outputFormat); callback.call(this, dataURL); canvas = null; }; img.src = url;