egret 长按二维码 将图片显示在dom中

可以使用如下方法

function egretToDom(obj:egret.DisplayObject){
    let scale = document.body.clientWidth / obj.stage.stageWidth;
    let renderTexture = new egret.RenderTexture;
    renderTexture.drawToTexture(obj);
    let base64 = renderTexture.toDataURL("image/png",new egret.Rectangle(0,0,obj.width,obj.height));
    
    let img :HTMLImageElement = new Image;
    document.body.appendChild(img);
    let style:object = {position:"absolute",left:obj.x*scale+"px" ,top:obj.y*scale+"px" ,width:obj.width*scale+"px",height:obj.height*scale+"px" };
    for (var key in style) {
        if (style.hasOwnProperty(key)) {
            let val = style[key];
            let sty = img.style;
            sty[key] = val;
        }
    }
    img.src = base64;
}

相关文章

此处评论已关闭