c***@qq.com
c***@qq.com
  • 发布:2019-05-25 20:01
  • 更新:2019-05-25 20:01
  • 阅读:3296

uniapp draw 时候报错! Cannot read property 'replace' of null 可是代码里面没有用到这个

分类:uni-app

小程序绘制图片然后保存,运行后直接报错 Cannot read property 'replace' of null

saveImage(){
console.log("1")
uni.showLoading({
title: '图片绘制中...',
})
var url = 'http://hzmt.cttv.co/NewsImag/d7aafa27a2aa4ecd940498f9d931692d.jpg'

//开始绘制图片,这边主要就是canvas写法了,uniapp官方:https://uniapp.dcloud.io/api/ui/canvas?id=%E5%9C%A8canvas%E4%B8%8A%E7%94%BB%E5%9B%BE  
const context = uni.createCanvasContext('myCanvas')  
context.drawImage(url,0, 0, this.windowWidth, this.windowHeight)  
context.drawImage(this.src,this.windowWidth/2-95/2, this.windowHeight/2,95,95)  
context.drawImage("http://www.cttv.co/NewsImag/201959123353502.jpg",(this.windowWidth-251)/2,7*(this.windowHeight/8),78,24)  
context.drawImage("http://hzmt.cttv.co/NewsImag/d7aafa27a2aa4ecd940498f9d931692d.jpg",(this.windowWidth-251)/2+88,7*(this.windowHeight/8),78,24)  
context.setFontSize(14)  
context.setFillStyle("#FEEDBB")  
context.fillText('邀请码:'+this.invitation,(this.windowWidth-251)/2+88+88,7*(this.windowHeight/8)+16)  
console.log("2")  

context.draw(false,function(){  
    uni.canvasToTempFilePath({  
        canvasId:'myCanvas',  
        success: function(res){  
            uni.hideLoading()  
            console.log(res.tempFilePath)  
            uni.saveImageToPhotosAlbum({  
                filePath:res.tempFilePath,  
                success : function(res){  
                    uni.showToast({title : '图片已保存'})  
                }  
            })  
        }  
    })  

})  

}

2019-05-25 20:01 负责人:无 分享
已邀请:

该问题目前已经被锁定, 无法添加新回复