📜  canvas js过滤灰度 - Javascript代码示例

📅  最后修改于: 2022-03-11 15:03:00.144000             🧑  作者: Mango

代码示例1
const img = document.querySelector('img');
const canvas = document.querySelector('canvas');
const ctx = canvas.getContext('2d');

img.onload = function() {
  canvas.width = img.width;
  canvas.height = img.height;
  ctx.filter = 'grayscale(1)';
  ctx.drawImage(img, 0, 0, img.width, img.height);
}