收藏
回答

Canvas绘制网络图片的问题,开发者工具显示,真机不显示?

var that = this

var ctx = wx.createCanvasContext('canvasNew', that);

wx.getImageInfo({

  src: 'https://xxxxxxxxxxxxxxxxxxxxxx.png',

  success: function (res) {

ctx.drawImage(res.path,0,0,res.width, res.height);

ctx.draw(false, ()=>{

  wx.canvasGetImageData({

    canvasId: 'canvasNew',

    x: 0,

    y: 0,

    width: res.width,

    height: res.height,

    success(result) {

      let data = result.data;

      for (let i = 0; i < result.width * result.height;i++){

        let R = data[i * 4 + 0];

        let G = data[i * 4 + 1];

        let B = data[i * 4 + 2];

var avg = (R * 0.3 + G * 0.59 + B * 0.11)

if (avg < 128) {

data[i * 4 + 0] = 2 * avg;

data[i * 4 + 1] = 0;

data[i * 4 + 2] = 0;

} else {

data[i * 4 + 0] = 255;

data[i * 4 + 1] = 2 * avg - 255;

data[i * 4 + 2] = 2 * avg - 255;

}

      }

      wx.canvasPutImageData({

        canvasId: 'canvasNew',

        x: 0,

        y: 0,

        width: res.width,

        data: data,

        success(res) { 

          console.log(res)

        },

fail(e) {

}

      }, that)

    },

fail(e){

console.log(e)

}

  }, that)

})

  }

})

最后一次编辑于  2023-04-21
回答关注问题邀请回答
收藏

1 个回答

  • 烟火
    烟火
    2023-04-21

    2023-04-21
    有用
    回复
登录 后发表内容