Javascript:将图像转换为base64还不完整?

时间:2019-05-31 06:39:11

标签: javascript canvas

我想将图像转换为base64,但值不完整?

<img crossorigin="anonymous" id="imageid" src="{{helper.photo_1}}" /> 
function getBase64Image(img) {
      var canvas = document.createElement("canvas");
      canvas.width = img.width;
      canvas.height = img.height;
      var ctx = canvas.getContext("2d");
      ctx.drawImage(img, 0, 0);
      var dataURL = canvas.toDataURL("image/png");
      return dataURL
}

var base64 = getBase64Image(document.getElementById("imageid"));
console.log(base64); // the value is not complete.

当我使用base64显示图像时,它是这样的:

0 个答案:

没有答案