收藏
回答

使用snapshot组件,发布上线后,截屏或写入文件失败是什么原因?

this.createSelectorQuery()

                .select("#snapshot")

                .node()

                .exec(res => {

                    const node = res[0].node

                    node.takeSnapshot({

                        type: 'arraybuffer',

                        format: 'png',

                        success: (res) => {

                            const f = `${wx.env.USER_DATA_PATH}/poster.png`

                            const fs = wx.getFileSystemManager();

                            // 将海报数据写入本地文件

                            fs.writeFileSync(f, res.data, 'binary')

                            this.saveImageToPhotosAlbum(f)

                        },

                        fail: (res) => {

                            console.log('截图错误:', res.errMsg)

                            wx.showToast({

                                title: '海报生成失败~',

                                icon: 'loading',

                                duration: 1000

                            });

                        },

                        complete: () => {

                            this.setData({

                                showServiceCode: false

                            })

                            wx.hideLoading()

                        }

                    })

                })


回答关注问题邀请回答
收藏

1 个回答

  • Eric Huang
    Eric Huang
    04-14

    应该是对应的小程序没有获得写入相册的权限

    04-14
    有用
    回复 3
    • 邵小来
      邵小来
      04-14
      麻烦问一下怎么获取哈?第一次开发小程序哈
      04-14
      回复
    • 邵小来
      邵小来
      04-14回复邵小来
      开发版和体验版本是ok的,发布上线后有问题
      04-14
      回复
    • 邵小来
      邵小来
      04-14
      能帮忙支持下么,很急
      04-14
      回复
登录 后发表内容