Laya1.x原生截屏方法
var self
= this;
var document
= Browser
.document
;
var _w_
= Browser
.width
;
var _h_
= Browser
.height
;
console.log("截屏尺寸:", _w_
, _h_
)
__JS__("html2canvas")(document
.getElementById("layaCanvas"), {
width
: _w_
,
height
: _h_
,
scale
: 2
})
.then(function (canvas
) {
var imgurl
= canvas
.toDataURL("png");
var img
= new Browser.window.Image();
img
.src
= imgurl
;
img
.setAttribute('crossOrigin', 'anonymous');
img
.onload = function () {
var cans
= document
.createElement("canvas");
cans
.width
= _w_
;
cans
.height
= _h_
;
var ctx
= cans
.getContext("2d");
console.log("cans", cans
)
cans
.style
.width
= _w_
;
cans
.style
.height
= _h_
;
ctx
.drawImage(img
, 0, 0);
var base64
= cans
.toDataURL("image/png");
console.log("base64_base64", base64
);
var testView
: ShareView
= new ShareView();
testView
.pivot(testView
.width
/ 2, testView
.height
/ 2);
testView
.pos(Laya
.stage
.width
/ 2, Laya
.stage
.height
/ 2);
testView
.startShare(cans
);
self
.addChild(testView
);
}
});
关键词:Laya Laya1. 截屏
转载请注明原文地址: https://lol.8miu.com/read-32614.html