cocoscreator截图分享出来是白屏是什么原因呢?

captureScreen:function(endCaptureCB,successCB,captureNode){
let node = new cc.Node();
node.parent = cc.director.getScene();
node.width = cc.view.getVisibleSize().width;
node.height = cc.view.getVisibleSize().height;
node.x = cc.view.getVisibleSize().width / 2;
node.y = cc.view.getVisibleSize().height / 2;
let camera = node.addComponent(cc.Camera);

    // 设置你想要的截图内容的 cullingMask
    camera.cullingMask = 0xffffffff;
    
    // 新建一个 RenderTexture,并且设置 camera 的 targetTexture 为新建的 RenderTexture,这样 camera 的内容将会渲染到新建的 RenderTexture 中。
    
    let texture = new cc.RenderTexture();
    let gl = cc.game._renderContext;
    texture.initWithSize(cc.visibleRect.width, cc.visibleRect.height, gl.STENCIL_INDEX8);
    camera.targetTexture = texture;
    
    // 渲染一次摄像机,即更新一次内容到 RenderTexture 中
    camera.render();
    
    // 这样我们就能从 RenderTexture 中获取到数据了
    let data = texture.readPixels();
    let width = texture.width;
    let height = texture.height;


    let picData = new Uint8Array(width * height * 4);
    let rowBytes = width * 4;
    for (let row = 0; row < height; row++) {
        let srow = height - 1 - row;
        let start = srow * width * 4;
        let reStart = row * width * 4;
        // save the piexls data
        for (let i = 0; i < rowBytes; i++) {
            picData[reStart + i] = data[start + i];
        }
    }

    endCaptureCB && endCaptureCB();
    var fileName = "share.png";
    let fullPath = jsb.fileUtils.getWritablePath() + fileName;
    if (jsb.fileUtils.isFileExist(fullPath)) {
        jsb.fileUtils.removeFile(fullPath);
    }
    let success = jsb.saveImageData(picData, width, height, fullPath);
    if (success) {
        cc.log("twl 截屏成功-->",fullPath,width,height);
        successCB && successCB(fullPath);
    }
    else {
        cc.error("save image data failed!");
    }
},

ios是白屏,android是好的

有知道的吗

顶一下,我也遇到这个问题了,我这边是在ios9上截图白屏,iOS10及以上截图就是正常的

我的就是ios 9.3.3 白屏

因为ios9对javaScript的支持不好

有什么办法解决吗?我用cocoscreator1.8.2版本是好的,现在换成2.0.9截屏就出问题了

暂时没有,你可以用这个网站查一下ios9上哪些语法不支持。然后自行排查相关模块是否用到了这些ios9不支持的语法。
https://caniuse.com/#search=let

你的最后怎么解决的呢?

creator 新版本在ios9 手机上截屏根本不能用,后面用oc代码实现截屏,具体代码如下

-(UIImage *)getImageWithFullScreenshot
{
BOOL ignoreOrientation = SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@“8.0”);

UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;    
    
CGSize imageSize = CGSizeZero;    
if (UIInterfaceOrientationIsPortrait(orientation) || ignoreOrientation)    
    imageSize = [UIScreen mainScreen].bounds.size;    
else    
    imageSize = CGSizeMake([UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width);    
    
UIGraphicsBeginImageContextWithOptions(imageSize, NO, [UIScreen mainScreen].scale);    
CGContextRef context = UIGraphicsGetCurrentContext();    
    
for (UIWindow *window in [[UIApplication sharedApplication] windows])    
{    
    CGContextSaveGState(context);    
    CGContextTranslateCTM(context, window.center.x, window.center.y);    
    CGContextConcatCTM(context, window.transform);    
    CGContextTranslateCTM(context, -window.bounds.size.width * window.layer.anchorPoint.x, -window.bounds.size.height * window.layer.anchorPoint.y);    
        
    // Correct for the screen orientation    
    if(!ignoreOrientation)    
    {    
        if(orientation == UIInterfaceOrientationLandscapeLeft)    
        {    
            CGContextRotateCTM(context, (CGFloat)M_PI_2);    
            CGContextTranslateCTM(context, 0, -imageSize.width);    
        }    
        else if(orientation == UIInterfaceOrientationLandscapeRight)    
        {    
            CGContextRotateCTM(context, (CGFloat)-M_PI_2);    
            CGContextTranslateCTM(context, -imageSize.height, 0);    
        }    
        else if(orientation == UIInterfaceOrientationPortraitUpsideDown)    
        {    
            CGContextRotateCTM(context, (CGFloat)M_PI);    
            CGContextTranslateCTM(context, -imageSize.width, -imageSize.height);    
        }    
    }    
        
    if([window respondsToSelector:@selector(drawViewHierarchyInRect:afterScreenUpdates:)])    
        [window drawViewHierarchyInRect:window.bounds afterScreenUpdates:NO];    
    else    
        [window.layer renderInContext:UIGraphicsGetCurrentContext()];    
        
    CGContextRestoreGState(context);    
}    
    
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();    
    
UIGraphicsEndImageContext();    
    
return image;    

}

1赞

感谢分享