2***@qq.com
2***@qq.com
  • 发布:2020-04-15 11:12
  • 更新:2021-02-07 10:51
  • 阅读:939

【报Bug】编译到iOS应用平台 自定义组件中进行uni.createCanvasContent('id', this) ,drawImage 等操作不生效

分类:uni-app

详细问题描述

编译到iOS应用平台 自定义组件中进行uni.createCanvasContent('id', this) ,drawImage 等操作不生效,Android平台是没问题的,没有开启V3编译

[内容]

[步骤]

// 子组件  
<canvas canvas-id="focusEnd" style="width: 750rpx; height: 1080rpx; position:fixed;right:-9000vw;"></canvas>  
//  
data() {  
  return {  
      focusEndBg: '',  
      qrcode: '',  
      logoIcon: '',  
      timeTop: '',  
      timeDown: ''  
  }  
},  
beforeMount () {  
uni.getImageInfo({  
      src: 'xxxxx',  
      success: (res) => {  
        this.focusEndBg = res.path  
      }  
    })  
    uni.getImageInfo({  
      src: 'xxxxxx',  
      success: (res) => {  
        this.timeTop = res.path  
      }  
    })  
    uni.getImageInfo({  
      src: 'xxxxx',  
      success: (res) => {  
        this.timeDown = res.path  
      }  
    })  
    uni.getImageInfo({  
      src: 'xxxxx',  
      success: (res) => {  
        this.logoIcon = res.path  
      }  
    })  
    uni.getImageInfo({  
      src: 'xxxxx',  
      success: (res) => {  
        this.qrcode = res.path  
      }  
    })  
},  
method: {  
  saveimage () {  
	uni.showLoading({  
				title: '正在保存图片'  
			})		  
			  
      // draw and save  
      let canvasWidth = uni.getSystemInfoSync().windowWidth  
      let canvasheight = parseInt(canvasWidth * 108 / 75)  
      const ppun = canvasWidth / 750 // 设置比例单位  
      let ctx = uni.createCanvasContext('focusEnd', this)  
      ctx.drawImage(this.focusEndBg, 0, 0, canvasWidth, canvasheight) // 画背景图  
      ctx.drawImage(this.logoIcon, 25 * ppun, 25 * ppun, 80 * ppun, 80 * ppun) // 画icon  
      ctx.setFillStyle('#666')  
      ctx.setFontSize(36 * ppun)  
      ctx.fillText('XXXX', 120 * ppun, 80 * ppun)  
      ctx.drawImage(this.timeTop, 240 * ppun, 200 * ppun, 260 * ppun, 130 * ppun) // 画时间上部分图片  
      ctx.setFillStyle('#FFF')  
      ctx.setFontSize(150 * ppun)  
      ctx.fillText(this.difftime, 330 * ppun - (this.difftime.toString().length - 1) / 2 * 75 * ppun, 460 * ppun)  
      ctx.drawImage(this.timeDown, 240 * ppun, 480 * ppun, 260 * ppun, 130 * ppun) // 画时间下部分图片  
      ctx.setFillStyle('#FFF')  
      ctx.setFontSize(38 * ppun)  
      ctx.fillText(this.startHM + ' ——— ' + this.endHM, 220 * ppun, 690 * ppun)  
      ctx.setFontSize(36 * ppun)  
      ctx.fillText('XXXX', 200 * ppun, 1050 * ppun)  
      ctx.drawImage(this.qrcode, 580 * ppun, 910 * ppun, 150 * ppun, 150 * ppun) // 画qrcode  
      ctx.draw(false, () => {  
				console.log('draw')  
        uni.canvasToTempFilePath({ // 画完之后将canvas区域保存图片  
					x: 0,  
					y: 0,  
					width: canvasWidth,  
					height: canvasheight,  
          canvasId: 'focusEnd',  
          quality: 1,  
          success: (res) => {  
						console.log(res, 'success')  
            uni.saveImageToPhotosAlbum({  
              filePath: res.tempFilePath,  
              success (res) {  
                uni.showToast({  
                  title: '图片已保存',  
                  icon: 'success'  
                })  
              }  
            })  
          },  
					fail: (err) => {  
						console.log(err, 'iii')  
					},  
					complete: (ccc) => {  
						uni.hideLoading()  
						console.log(ccc, 'ccc')  
					}  
        }, this)  
      })  
    },  
}  

这个saveimage方法是绑定到子组件的某个节点上的,在父节点上点击这个节点去触发这个事件
[结果]
Android、微信小程序平台可以成功绘制并保存图片到相册,iOS应用保存不了,也绘制不出,并且没有任何报错
[期望]
所有平台都可以正常绘制canvas和保存图片
[如果语言难以表述清晰,拍一个视频或截图,有图有真相]

IDE运行环境说明

HBuilderX 2.6.11.20200409

Mac: 10.15.4

uni-app运行环境说明

小程序 + 双端应用

iOS 10.3.3 、 13

HBuilderX创建

[编译模式说明:自定义组件模式?纯nvue模式?v3模式?]

App运行环境说明

[Android版本号]

[iOS版本号]

[手机型号]

[模拟器型号]

附件

[IDE问题请提供HBuilderX运行日志。菜单帮助-查看运行日志,点右键打开文件所在目录,将log文件压缩成zip包上传]

[App问题请提供可重现问题的代码片段,你补充的细一点,问题就解决的快一点]

[App安装包或H5地址]

[可重现代码片段]

联系方式

[QQ] 2510952840

2020-04-15 11:12 负责人:无 分享
已邀请:
2***@qq.com

2***@qq.com (作者)

我已经发现为什么了,在这之前希望官方可以修复一下:
canvas中,如果drawImage()中的图片,是网络图片,微信小程序官方是说明了需要使用getImageInfo()或者downloadFile()这两个api先把图片下载到本地临时文件目录,然后才可以,在uni里面如果使用了getImageInfo()将图片下载到本地的话在Android上及其他小程序上不会有问题,但是在iOS应用上就不生效,导致之后的操作失败,需要用downloadFile()去获取文件到本地才可以!!!!!!

希望官方可以抹平这里的差异或者在文档上声明一下!

wwwwating

wwwwating

ios下createCanvasContext无法生效是怎么回事啊

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