java - 找不到符号编译器错误

标签 java constructor find symbols

我在为我的 Java 编程课完成的作业中遇到问题。我要做的是在具有纯色背景的图像上执行色度键技术。更多信息可查看here 。当我为方法添加两个对象参数时,我创建的方法就可以工作。但是,当我将参数放入构造函数然后尝试使用该方法时,出现编译器错误。我的类在下面(我必须使用两个不同的类,一个用于方法,一个用于测试)。任何帮助将不胜感激,我是java新手,最简单的路线是最好的。

public class ChromaKey
{
    public ChromaKey(Picture backgroundDelete, Picture backgroundImage)
    {  
    }
    public void chromaKey()
    {        
         int redValue = 0; int greenValue = 0; int blueValue = 0;      
        Color pixelColor = null;   
        Color pixelColor1 = null;   
        for(int y = 0; y < backgroundImage.getHeight(); y++)             
        {
            for(int x = 0; x < backgroundImage.getWidth(); x++)    
            {
                Pixel targetPixel = new Pixel(backgroundImage,x,y);   
                Pixel targetPixel1 = new Pixel(backgroundDelete,x,y);

                targetPixel = backgroundImage.getPixel(x,y);                
                pixelColor = targetPixel.getColor();

                targetPixel1 = backgroundDelete.getPixel(x,y);
                pixelColor1 = targetPixel1.getColor();

                int targetRed = pixelColor1.getRed();
                int targetBlue = pixelColor1.getGreen();
                int targetGreen = pixelColor1.getBlue();

                int backgroundRed = pixelColor.getRed();
                int backgroundGreen = pixelColor.getGreen();
                int backgroundBlue = pixelColor.getBlue();

                if(targetRed >= 200 && targetBlue >= 200 && targetGreen >= 200) 
                {
                    targetPixel1.setRed(backgroundRed);
                    targetPixel1.setGreen(backgroundGreen);
                    targetPixel1.setBlue(backgroundBlue);

                }
            }
        }
        backgroundImage.show();
        backgroundDelete.show();
    }
}

最佳答案

有一些东西看起来缺失了。首先,您是否导入 Color 和 Pixel 类,或者它们是否包含在与 ChromaKey 类相同的包中?

其次,您需要将backgroundImage和backgroundDelete定义为类变量,以便在您的void chromaKey()方法中调用它(注意我添加的“private Picture backgroundDelete;”行,以及构造函数中的赋值):

公共(public)类 ChromaKey {

private Picture backgroundDelete;
private Picture backgroundImage;


public ChromaKey(Picture backgroundDelete, Picture backgroundImage)
{  
    this.backgroundDelete = backgroundDelete;
    this.backgroundImage = backgroundImage;
}
public void chromaKey()
{        
     int redValue = 0; int greenValue = 0; int blueValue = 0;      
    Color pixelColor = null;   
    Color pixelColor1 = null;   
    for(int y = 0; y < backgroundImage.getHeight(); y++)             
    {
        for(int x = 0; x < backgroundImage.getWidth(); x++)    
        {
            Pixel targetPixel = new Pixel(backgroundImage,x,y);   
            Pixel targetPixel1 = new Pixel(backgroundDelete,x,y);

            targetPixel = backgroundImage.getPixel(x,y);                
            pixelColor = targetPixel.getColor();

            targetPixel1 = backgroundDelete.getPixel(x,y);
            pixelColor1 = targetPixel1.getColor();

            int targetRed = pixelColor1.getRed();
            int targetBlue = pixelColor1.getGreen();
            int targetGreen = pixelColor1.getBlue();

            int backgroundRed = pixelColor.getRed();
            int backgroundGreen = pixelColor.getGreen();
            int backgroundBlue = pixelColor.getBlue();

            if(targetRed >= 200 && targetBlue >= 200 && targetGreen >= 200) 
            {
                targetPixel1.setRed(backgroundRed);
                targetPixel1.setGreen(backgroundGreen);
                targetPixel1.setBlue(backgroundBlue);

            }
        }
    }
    backgroundImage.show();
    backgroundDelete.show();
}

}

关于java - 找不到符号编译器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23636815/

相关文章:

c++ - 拷贝构造函数需要调用依赖对象的方法,但是构造函数不能是virtual

Java执行命令行程序 'find'返回错误

java - Spark : Partitioning an RDD created from HBase data

java - 将字符串数组转换为字节数组

c++ - 在使用 push_back() 实例化对象时,如何将指针传递给对象的构造函数?

Java:Getter、Setter 和构造函数

java - 需要帮助来理解此代码以找到给定数字中 1 的位置

java - 如何使用 MULE ESB 将邮件附件传递给 POJO 对象

c++ - QPlainTextEdit - 搜索文档到最后,然后再从头开始

linux - grep 不显示路径/文件 :line