在start方法的下一帧设置gfx.ColorAttachment参数就可以了
protected start() {
if(sys.platform == sys.Platform.ANDROID) {
this._bgNode.setScale(v3(1,-1,1));
}
this.scheduleOnce(()=>{
if(sys.platform == sys.Platform.ANDROID) {
const gfxAPI = director.root.pipeline.device.gfxAPI;
this.screenShotRT = new RenderTexture();
const colorAttachment = new gfx.ColorAttachment(
gfx.Format.RGBA8, // 颜色格式
gfx.SampleCount.ONE, // 采样数
gfx.LoadOp.CLEAR, // 加载操作:清除
gfx.StoreOp.STORE, // 存储操作:保存
null, // 通用屏障(可选)
false // 是否使用通用布局
);
const passInfo = new gfx.RenderPassInfo(
[colorAttachment], // 颜色附件数组
null
);
this.screenShotRT.reset({
name: 'CustomRenderTexture',
width:750,
height:1650,
passInfo:passInfo
});
this._camera.targetTexture = this.screenShotRT
this._camera.clearFlags = gfx.ClearFlagBit.COLOR;
this._camera.clearColor = new Color(0, 0, 0, 0);
}
});
}
screenShotAndSave(shareScene: WXScene) {
this.scheduleOnce(()=>{
let pixelData = this.screenShotRT.readPixels();
…
});
}