//获取指定图片地址的base64值,
function getBase64Image(url, callback){
var canvas = document.createElement("CANVAS");
var ctx = canvas.getContext('2d');
var img = new Image;
img.crossOrigin = 'Anonymous';
img.src = 'res/raw-assets/' + url;//如:'res/raw-assets/' + "public/skin/frame_1.png"
img.onload = function(){
canvas.height = img.height;
canvas.width = img.width;
ctx.drawImage(img, 0, 0);
var dataURL = canvas.toDataURL('image/png');
canvas = null;
if( callback ) callback(dataURL);
}
}
转自:https://forum.cocos.org/t/web-resources-base64/60759