收藏
回答

电脑上能进行保存操作,但是真机调试无法保存

框架类型 问题类型 操作系统 操作系统版本 手机型号 微信版本
小程序 Bug Android Andorid12 redmik30pro 8.0.47
downloadImages: function (path, context, p{
    const that = this;
    const ob = path.split('Url')[0];
    return new Promise((resolve, reject) => {
      wx.downloadFile({
        urlString(this.data[path]),
        success(res) {
          context.drawImage(res.tempFilePath, that.data[ob].x, that.data[ob].y, p, p);
          context.draw(true, () => {
            resolve(); // 成功时 resolve
          });
        },
        fail(error) {
          console.log(error);
          reject(error); // 失败时 reject
        }
      });
    });
  },


  saveImagefunction () {
    this.getCanvas().then(async () => {
        const context = wx.createCanvasContext('myCanvas');
        context.width = this.data.canvasWidth;
        context.height = this.data.canvasHeight;
        context.setFillStyle('white');
        context.fillRect(00600700);
        async function getSystemInfoAsync(context{
            return new Promise((resolve, reject) => {
                wx.getSystemInfo({
                    success(res) => {
                        var rpx = 150;
                        var px = rpx * (res.windowWidth / 750);
                        context.setData({
                            imgSize: px,
                        });
                        resolve();
                    },
                    fail(error) => {
                        reject(error);
                    }
                });
            });
        }
        await getSystemInfoAsync(this);
        const p = this.data.imgSize
        const that = this;
        console.log("sss");
        // 绘制图片
        if (this.data.faceUrl) {
            await this.downloadImages('faceUrl', context, p);
        }
        if (this.data.eyeUrl) {
            await this.downloadImages('eyeUrl', context, p);
        }
        if (this.data.eyebrowUrl) {
            await this.downloadImages('eyebrowUrl', context, p);
        }
        if (this.data.mouthUrl) {
            await this.downloadImages('mouthUrl', context, p);
        }
        if (this.data.gestureUrl) {
            await this.downloadImages('gestureUrl', context, p);
        }
        if (this.data.footUrl) {
            await this.downloadImages('footUrl', context, p);
        }
        if (this.data.decorateUrl) {
            await this.downloadImages('decorateUrl', context, p);
        }
        console.log("aaa");
        context.draw(truefunction () {
            // 将Canvas内容保存为本地文件
            console.log("bbb")
            wx.canvasToTempFilePath({
                canvasId'myCanvas',
                successfunction (res{
                    // 保存到相册
                    wx.saveImageToPhotosAlbum({
                        filePath: res.tempFilePath,
                        successfunction () {
                            wx.showToast({
                                title'保存成功',
                                icon'success',
                                duration2000
                            });
                        },
                        failfunction (error{
                            console.error('保存失败', error);
                        }
                    });
                    // 清空 Canvas
                    context.clearRect(00, that.data.canvasWidth, that.data.canvasHeight);
                    context.draw(); // 重新绘制空画布
                },
                failfunction (error{
                    console.error('canvasToTempFilePath 失败', error);
                }
            });
        });
    })
},
回答关注问题邀请回答
收藏

3 个回答

登录 后发表内容