找不到符号编译错误

时间:2014-05-13 16:30:16

标签: 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();
    }
}

1 个答案:

答案 0 :(得分:1)

有一些看起来像是他们缺失的东西。首先,您是导入Color和Pixel类,还是与ChromaKey类包含在同一个包中?

其次,你需要将backgroundImage和backgroundDelete定义为一个类变量,以便在你的void chromaKey()方法中调用它(注意&#34;私有图片backgroundDelete;&#34;我添加的行,以及赋值在你的构造函数中):

公共课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();
}

}