📅  最后修改于: 2022-03-11 15:03:06.658000             🧑  作者: Mango
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);
}