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

        }

  • 相关阅读:
    get与post区别
    Django 一对多关系
    Java是怎么执行的?
    java之《图书管理系统》庖丁解牛
    商城有一个抽奖活动,作为用户购买三件商品才能抽奖一次,怎么分析测试点
    DSPE-PEG-VIP,磷脂-聚乙二醇-血管活性肠肽VIP,VIP修饰脂质体供应
    【软件测试】常用ADB命令
    剑指OfferⅡ 045.二叉树最底层最左边的值 dfs
    【Leetcode-面试经典150题-day22】
    MySQL日志管理和完全备份增量备份与恢复
  • 原文地址:https://blog.csdn.net/tang_bo_hu_2011/article/details/126990433