小游戏渲染模式为Webgl时,canvas.toTempFilePath截图保存图片后,图片有严重的边缘残影。渲染模式为canvas时,没有这个问题。
在小游戏里是正常的,显示没有任何问题。
代码:
var canvas = cc.game.canvas;
var height = canvas.height;
var width = canvas.width;
canvas.toTempFilePath({
x: 0,
y: 0,
width: width,
height: height,
destWidth: width,
destHeight: height,
success (res) {
console.log(res);
wx.saveImageToPhotosAlbum({
filePath: res.tempFilePath,
success:function(r){
console.log(r);
cc.instantiate(that.tipsPrefab).getComponent('Tips').init(that.node, '保存成功', 0, 0, 500);
},
fail:function(r){
console.log(r);
}
})
}
})
你们有线上的小游戏可以复现吗,复现步骤是?
这个问题所在的版本还没上线
这样吧,麻烦你通过微云给一下我代码示例,辛苦了
https://www.weiyun.com/
示例代码包:https://share.weiyun.com/5cTzaKF
你好问题已复现,我们查一下
棒~
这是正常效果:
我的工程里有cocos2d-js引擎,代码片段也超过200K,提交不了片段。
这是核心代码:
saveShotToAlbum:
function
(){
var
that =
this
;
wx.getSetting({
success(res) {
if
(!res.authSetting[
'scope.writePhotosAlbum'
]) {
wx.authorize({
scope:
'scope.writePhotosAlbum'
,
success() {
shotAndSaveImage();
},
fail:
function
(res) {
}
})
}
else
{
shotAndSaveImage();
}
}
});
function
shotAndSaveImage(){
var
canvas = cc.game.canvas;
var
height = canvas.height;
var
width = canvas.width;
canvas.toTempFilePath({
x: 0,
y: 0,
width: width,
height: height,
destWidth: width,
destHeight: height,
success (res) {
console.log(res);
wx.saveImageToPhotosAlbum({
filePath: res.tempFilePath,
success:
function
(r){
console.log(r);
},
fail:
function
(r){
console.log(r);
}
})
}
})
}
},
麻烦给个相关的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html),我们定位下问题
也提供下截图正常和截图残影的对比照
toTempFilePath
的 fileType 设置为'jpg'时, 没有问题。默认“png”时会出现上述情况。