• Creator 2.4.x 分享游戏图片


    getPicByUrl(callback: Function, url: string) {

            测试用的地址来的

            // if (!url) url = "http://xx.xx/html5/share1.png";

            let fileDir = `${jsb.fileUtils.getWritablePath()}madherogo`;

            var currentDate = new Date();

            var fileName = currentDate.getFullYear() + "" + (currentDate.getMonth() + 1) + ""

                + currentDate.getDate() + "" + currentDate.getHours() + "" + currentDate.getMinutes() + currentDate.getSeconds();

            fileName = fileName + ".png";

            let fullPath = `${fileDir}/${fileName}`;

            if (!jsb.fileUtils.isDirectoryExist(fileDir)) {

                jsb.fileUtils.createDirectory(fileDir);

            }

            if (jsb.fileUtils.isFileExist(fullPath)) {

                jsb.fileUtils.removeFile(fullPath);

            }

            let xhr = new XMLHttpRequest();

            xhr.onreadystatechange = () => {

                if (xhr.readyState === 4 && xhr.status === 200) {

                    if (xhr.response) {

                        let u8a = new Uint8Array(xhr.response);

                        // let success = jsb.fileUtils.writeValueMapToFile(u8a, fullPath);

                        let success = jsb.fileUtils.writeDataToFile(u8a, fullPath);

                        // let picData = this.filpYImage(u8a, 500, 400);

                        // let success = jsb.saveImageData(picData, 500, 400, fullPath);

                        if (success) {

                            // eslint-disable-next-line no-console

                            console.log('截屏成功,fullPath,width,height = ', fullPath);

                            callback(fullPath);

                        }

                        else {

                            cc.error('截屏失败!');

                        }

                    }

                }

            };

            xhr.responseType = 'arraybuffer';

            xhr.open("GET", url, true);

            xhr.send();

        }

  • 相关阅读:
    通过开源如何赚钱生存发展
    《从零开始的Java世界》10File类与IO流
    数据分析-Pandas两种分组箱线图比较
    C++ 类的继承(Inheritance)
    tomcat10版本升级导致jar引入问题
    Linux进程控制
    查看实时日志
    浅谈RPC
    部署LVS+Keepalived高可用群集(抢占模式,非抢占模式,延迟模式)
    契约测试(中):利用PACT做契约测试
  • 原文地址:https://blog.csdn.net/tang_bo_hu_2011/article/details/126990433