[]drawToCanvas无法截取到有子元素。


78ADE23A-827E-4D50-A8EF-E049EB513DB2.png

我这里sp2有子元素sp3
截取到的图片,只有sp2图片,sp3图片没有。
已邀请:

Monica - 知识达人

赞同来自:

以下是我这边的测试代码以及例子,没有问题的!
1.png


2.png

liqunyang

赞同来自:

// test drawToCanvas
const sp1 = new Sprite();
sp1.loadImage('bet/cheer_1_3.png');

const sp2 = new Sprite();
sp2.x = 100;
sp2.loadImage('bet/cheer_1_4.png');
sp1.addChild(sp2);
this.addChild(sp1);

const htmlCanvas = sp1.drawToCanvas(640, 200, 0, 0);
const canvas = htmlCanvas.getCanvas();
trace(canvas.toDataURL('image/png'));
const texture = new Laya.Texture(htmlCanvas);
const sp = new Sprite();
sp.graphics.drawTexture(texture);
this.shot.addChild(sp);
对,是可以的。当时drawToCanvas的第一个参数设置小了,没看到后面的元素。
这里还有一个问题:
        const sp1 = new Laya.Image();
sp1.skin = 'bet/cheer_1_3.png';
this.addChild(sp1);

const htmlCanvas = sp1.drawToCanvas(640, 200, 0, 0);
const canvas = htmlCanvas.getCanvas();
trace(canvas.toDataURL('image/png'));
const texture = new Laya.Texture(htmlCanvas);
const sp = new Sprite();
sp.graphics.drawTexture(texture);
this.shot.addChild(sp);
为什么我这里sp1是Image类,无法截图。

要回复问题请先

商务合作
商务合作