let canvas = document.createElement('canvas');
canvas.width = width;
canvas.height = height;
let ctx = canvas.getContext('2d');
let gpTexture = new cc.RenderTexture(); //绘制
//@ts-ignore
gpTexture.initWithSize(width, height, cc.game._renderContext.STENCIL_INDEX8);
this.gpCamera.targetTexture = gpTexture;
this.gpCamera.render(this.node);//相机绘制,将屏幕上的内容更新到renderTexture中
let data = gpTexture.readPixels();//读取renderTexture中的数据
// data = this.changeAlpha(data);
let rowBytes = width * 4;
for (let row = 0; row < height; row++) {
let srow = height - 1 - row;
let imageData = ctx.createImageData(width, 1);
let start = srow * width * 4;
for (let i = 0; i < rowBytes; i++) {
imageData.data[i] = data[start + i];
}
ctx.putImageData(imageData, 0, row);
}
let _tempFilePath = await canvas.toTempFilePathSync(
{
x: 0,
y: 0,
width: width,
height: height,
destWidth: 380,
destHeight: 380,
fileType: 'png',
quality: 1
});
wx.previewImage({
urls: [_tempFilePath]
})
明明是透明部分 怎么就变成黑色了
加个白色背景
这是手机的背景色,图片是png没错,用ps打开还是透明
我用Graphics组件绘画 然后截图保存 没有背景图 微信开发工具调试 显示是正常的 但是 微信上测 图片就有黑色了,好像是 微信存的图片默认Alpha值都是100%