• 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();

        }

  • 相关阅读:
    代码随想录刷题|LeetCode 198.打家劫舍 213.打家劫舍II 337.打家劫舍III
    java计算机毕业设计个人网站设计源程序+mysql+系统+lw文档+远程调试
    SSM+图书馆电子文件资源管理 毕业设计-附源码091426
    单向环形链表构建(思路分析) [Java][数据结构]
    sql按要求写语句如图
    kafka随笔
    selenium自动化测试-获取黄金实时价格
    Springboot 解决linux服务器下获取不到项目Resources下资源
    linux的man命令
    web目录扫描工具汇总
  • 原文地址:https://blog.csdn.net/tang_bo_hu_2011/article/details/126990433