js-将在线图片转成Base64的图片

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/smj20170417/article/details/80691954
convertImgToBase64:function(url, outputFormat,callback){
	var canvas = document.createElement('CANVAS'),
    ctx = canvas.getContext('2d'),
    img = new Image();
    img.crossOrigin = 'Anonymous';
    img.onload = function(){
     canvas.height = img.height;
     canvas.width = img.width;
     ctx.drawImage(img,0,0);
     var dataURL = canvas.toDataURL(outputFormat || 'image/png');
     callback.call(this, dataURL);
     canvas = null; 
  };
  img.src = url;}



展开阅读全文

没有更多推荐了,返回首页