图像过滤器中的javascript错误

图像过滤器中的javascript错误,javascript,Javascript,因此,我正在制作一个基本的应用程序,将图像过滤器添加到图像中。这是代码 class ImageUtils { static getCanvas(w, h) { var c = document.querySelector("canvas"); c.width = w; c.height = h; return c; } static getPixels(img) { var c = ImageUtils.getCanvas(img.width, img

因此,我正在制作一个基本的应用程序,将图像过滤器添加到图像中。这是代码

class ImageUtils {

static getCanvas(w, h) {
    var c = document.querySelector("canvas");
    c.width = w;
    c.height = h;
    return c;
}

static getPixels(img) {
    var c = ImageUtils.getCanvas(img.width, img.height);
    var ctx = c.getContext('2d');
    ctx.drawImage(img, 0, 0);
    return ctx.getImageData(0,0,c.width,c.height);
}

static putPixels(imageData, w, h) {
    var c = ImageUtils.getCanvas(w, h);
    var ctx = c.getContext('2d');
    ctx.putImageData(imageData, 0, 0);
}

}

function getRandomInt(min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;

...

function makeMoreRed(img, adjustment){

 var pixels = ImageUtils.getPixels(img);
 var length = pixels.data.length;
 var data = pixels.data;

 for(var r = 0; r < length; r += 4) {
  data[r] += adjustment;
 }
 ImageUtils.putPixels(pixels, img.width. img.height);
}

...

$(document).ready(function() {
 var img = new Image();
 img.src = "img/cat.jpg";
 makeMoreRed(img, 50);
});
类ImageUtils{
静态getCanvas(w,h){
var c=document.querySelector(“canvas”);
c、 宽度=w;
c、 高度=h;
返回c;
}
静态像素(img){
var c=ImageUtils.getCanvas(img.width,img.height);
var ctx=c.getContext('2d');
ctx.drawImage(img,0,0);
返回ctx.getImageData(0,0,c.宽度,c.高度);
}
静态像素(图像数据,w,h){
var c=ImageUtils.getCanvas(w,h);
var ctx=c.getContext('2d');
ctx.putImageData(imageData,0,0);
}
}
函数getRandomInt(最小值、最大值){
返回Math.floor(Math.random()*(max-min+1))+min;
...
功能MakeMored(img,调整){
var pixels=ImageUtils.getPixels(img);
变量长度=pixels.data.length;
var数据=像素。数据;
对于(var r=0;r
当我启动网页时,Chrome会抛出这个错误

这没有任何意义,因为函数末尾只有一个分号

有没有解决方法来解决这个问题,因为在这里你可以看到顶部图像(应该被过滤的图像)没有变化
你写道,这只是一个打字错误

ImageUtils.putPixels(pixels, img.width. img.height);

但是宽度后面必须有逗号而不是点。

发生错误的原因是您使用了
而不是

ImageUtils.putPixels(pixels, img.width. img.height);
比较:

ImageUtils.putPixels(pixels, img.width, img.height);

请不要使用StackOverflow检查您的语法,我们是来帮助您解决实际问题的。

您缺少逗号
宽度和高度之间的逗号
ImageUtils.putPixels(pixels,img.width,img.height)
;欢迎来到StackOverflow a1phabeta。我完全理解您对错误的失望,但称之为愚蠢会让人们对您的问题持否定态度。此外,如果可能,请始终尝试首先在JSFIDLE上测试您的代码,看看是否有错误发生。如果有,您可以发布代码并链接到您的测试,并且您会更快地得到答案!