[0]drawToTexture(1600,1600,0,0)截图出来部分图像丢失

简单的创建一个sprite,对sprite进行1600,1600的颜色绘制,对其截图就会出现图片丢失。
 
private nsp:Laya.Sprite;
    init(): void {
        this.nsp=new Laya.Sprite();
        this.nsp.graphics.drawRect(0,0,1600,1600,"#ff0000");
        this.nsp.mouseThrough=true;
        Laya.stage.addChild(this.nsp);
        this.nsp.on(Laya.Event.CLICK,this,this.drawImg,null)
        //nsp.texture=Laya.stage.drawToTexture(100,100,0,0);
    }
    drawImg(e:Event=null):void{
        var copySpr:Laya.Sprite=new Laya.Sprite();
        copySpr.texture=this.nsp.drawToTexture(1600,1600,0,0) as Laya.Texture;
        this.nsp.removeSelf();
        copySpr.scale(.1,.1);
        Laya.stage.addChild(copySpr);
    }
QQ图片20220809182809.png
已邀请:

李文

赞同来自:

用copySpr.graphics.drawTexture试试

18688961270

赞同来自:

截图的最大范围是舞台的宽高,所以原图的尺寸不能超过舞台的宽高,如果原图大于的舞台宽高就要进行缩放到舞台范围内,这样截图就不会有问题了,具体代码如下:
let scl = Math.min(Laya.stage.width / nsp.width, Laya.stage.height / nsp.height);
        nsp.scale(scl, scl);
        let iw = 1600 * scl;
        let ih = 1600 * scl;
        let hc: Laya.HTMLCanvas = this.img.drawToCanvas(iw, ih, nsp.x, nsp.y);
        let sp = new Laya.Sprite();
        sp.texture = hc.getTexture() as Laya.Texture;
        Laya.stage.addChild(sp);
        nsp.visible=false;
 

要回复问题请先

商务合作
商务合作