cocos2d-js 分享截屏-js代码

//depthStencilFormat == 0x88F0
//这样就可以分享带有scrollview的界面截屏了。否则会出现空白的部分

captureAndShareToWX: function (node, depthStencilFormat) {
            var winSize = cc.director.getWinSize();
            var texture = new cc.RenderTexture(winSize.width, winSize.height, null, depthStencilFormat);
            if (!texture)
                return;

            texture.retain();

            texture.setAnchorPoint(0, 0);
            texture.begin();
            node.visit();
            texture.end(); //实现截屏的部分

            var time = timestamp2time(Math.round((new Date()).valueOf() / 1000));//时间转化格式
            var nameJPG = "ss-" + time + ".jpg";

            if (cc.sys.os == cc.sys.OS_ANDROID) { //保存图片路径
                texture.saveToFile(nameJPG, cc.IMAGE_FORMAT_JPEG, false, function (renderTexture, str) {
                    texture.release();
                    jsb.reflection.callStaticMethod( // 调用底包的方法,实现分享到微信
                        packageUri + "/utils/WeixinUtil",
                        "sharePic",
                        "(Ljava/lang/String;Z)V",
                        nameJPG,
                        false
                    );
                });
            }
            else if (cc.sys.os == cc.sys.OS_IOS) {
                texture.saveToFile(nameJPG, cc.IMAGE_FORMAT_JPEG, true, function (renderTexture, str) {
                    texture.release();
                    jsb.reflection.callStaticMethod(//调用底包方法分享到微信
                        "WXUtil",
                        "sharePic:imageName:sceneType:",
                        jsb.fileUtils.getWritablePath(),
                        nameJPG,
                        0
                    );
                });
            }
        },

猜你喜欢

转载自blog.csdn.net/w_han__/article/details/78721738