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;
}
最后更新于 2017-06-27 15:13:09 并被添加「egret 长按二维码 将图片显示在dom中」标签,已有 662 位童鞋阅读过。
此处评论已关闭