怎样加载base64的图片?

因为没有3d的label,所以我想通过canvas生成输出base64的文字图片,然后场景中通过base64加载图片,在creator中可以通过以下方式加载,但在creator3d中没有对应的方法,我应该怎样做。
let strImg = “data:image/jpeg;base64,” + strQR;
let img = new Image();
img.src = strImg
let texture = new cc.Texture2D();
texture.initWithElement(img);
texture.handleLoadedTexture();
this.aSprite.spriteFrame = new cc.SpriteFrame(texture);

自己顶顶:sob:

你这个问题提的让我想了半天,最后一拍大腿想起来canvas可以直接扔到Texture2D里渲染的。这个变量名是creator2d里用的renderTexture,懒得改了。

const img = new Image();
img.src =
“data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAgAAAAIACAYAAAD0eNT6AAASeklEQVR4nO3dQXIbV2KA4e6GRKs0Uymvs01yhqmpVM4xq3iVY2U1d5gbTCqXmLXXqamMy5bV3VlM0QaeQBC0ZILh/30bmxQFNiCQ+PHe69fzN9/+4U8TAJCy3PoAAIDnJwAAIEgAAECQAACAoDfnPvm/3/7Pfzz3gQDP4/Dm7fLm3Zt/vfuHu2/2aZ7nad8//PXDH//23d/+/GZb9lsfH/Dl/fYfv/7P8XNGACBo3/b50sfA6ycAIGjbt5N3+vMye+cPMQIAgg6Hw8nHRgCgRwBAkBd8QAAApgAgSABAkBd8QAAApgQgSAAAQJAAAIAgAQBB67re+hCAGxMAEDTuAwD0CAAACBIAgNMCIUgAQJA1AIAAAOwDAEECAIIsAgQEAAAECQAIMuQPCAAIsuofEAAQZAQAEAAQNI4AGBGAHgEAQfYBAAQAYEoAggQAAAQJAAha5sU7fogTAIBFgBAkACDICz4gAACLACFIAABAkAAAgCABAFgTAEECAILGnQCtAYAeAQBB9gEABAAEbfvmYkAQJwAAFweCIAEAQYfD4eRjUwLQIwAAIEgAQJBV/4AAgKBx0Z9FgNAjACDIoj9AAECQRX+AAICgccjfmgDoEQAQZAoAEAAQNO4DAPQIAAgy5A8IAAgarwUA9AgACDIFAAgACDIFAAgAwE6AECQAIMg+AIAAgCAv+IAAgCBD/oA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egQAAAQJAMAUAATN33z7hz/d+iAAgOdlBAAAggQAAAQJAAAIEgAAEPR/qW0Ess3GPt4AAAAASUVORK5CYII=”;
const tex = new Texture2D();

img.onload = function () {
  tex.reset({
    width: img.width,
    height: img.height,
  });
  tex.uploadData(img, 0, 0);
  tex.loaded = true;
  const sp = new SpriteFrame();
  sp.texture = tex;
  self.sp.spriteFrame = sp;
};

感谢感谢。