标签:nload png tco cti keyword ring contex context url
/** * 将图片转换为Base64 */
function image2Base64(img)
{
var canvas = document.createElement("canvas");
canvas.width = img.width; canvas.height = img.height;
var ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0, img.width, img.height);
var dataURL = canvas.toDataURL("image/png");
return dataURL;
}
/** * 获取图片Base64编码 */
function getImgBase64()
{
var base64=""; var img = new Image();
img.src="img/test.jpg";
img.onload=function(){
base64 = image2Base64(img);
}
}
getImgBase64();
标签:nload png tco cti keyword ring contex context url
原文地址:https://www.cnblogs.com/jimmyLei/p/9052910.html