小程序图片相关操作

本文介绍小程序中如何处理图片,包括在图片上根据坐标绘制图形和获取图片拍摄角度进行旋转后上传。首先,创建canvas并计算缩放比例,然后利用小程序API进行图形绘制。对于图片旋转,通过getImageInfo获取exif信息,使用translate和rotate进行调整,并通过canvasToTempFilePath和uploadFile完成上传。
摘要由CSDN通过智能技术生成

小程序图片相关操作

q1:在图片上根据传过来的坐标绘制图形

imageWidth = res.width;
        imageHeight = res.height;
        wx.getSystemInfo({
          success (res) {
            windowWidth = res.windowWidth
            windowHeight = res.windowHeight 
          }
        })
        let a = windowWidth/imageWidth/2;
        let b = windowHeight/imageHeight/2;
        let widRate = a.toFixed(2);
        let heiRate = b.toFixed(2);
        
        const ctx = wx.createCanvasContext('shareCanvas');
        let result = JSON.parse(options.item)
        let coordinate = result.coordinate
        let first = coordinate[0];
        let second = coordinate[1];
        let thrid = coordinate[2];
        let fourth = coordinate[3];
      
        ctx.drawImage(imageUrl, 0, 0,windowWidth/2,windowHeight/2);
        ctx.moveTo(first[0]*widRate, first[1]*heiRate)
    
        ctx.lineTo(second[0]*widRate, second[
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值