1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
var picurl = "http://wx.qlogo.cn/mmopen/p41z82bcTPWp2CcBuSS1ZUSNbUROqNaLUjsqibhMicnddo6AFFKcMD56zV24srtNeKcI8cibEibibSDvK43PBhAKODTwzy5DfxFXe/132"; var img = new Image, canvas = document.createElement("canvas"), ctx = canvas.getContext("2d"), src = picurl.replace("http://wx.qlogo.cn","//wq.jd.com"); img.crossOrigin = "Anonymous"; img.onload = function() { canvas.width = img.width; canvas.height = img.height; ctx.drawImage( img, 0, 0 ); localStorage.setItem( "savedImageData", canvas.toDataURL("image/png") ); } img.src = src;
上传图片部分代码:
$.ajax({ type: 'POST', url: loadJs.addToken('http://wq.jd.com/activetmp/promotepic/promoteaddpic', "j132"), data: { filename: new Date().getTime()+''+Math.floor(Math.random()*10000) + '.jpg', content: base64pic, active: "shotpic20160901" }, dataType: 'json', xhrFields: { withCredentials: true }, success: function(data) { if (picdata.id == 1 && picdata.msg) { var imgPre = 'http://img10.360buyimg.com/promotepic/'; var photo = imgPre + picdata.msg; $("#cardImg")[0].onload = function() { }; $("#cardImg").attr("src",photo); } }, error:function(data){ } });
|