gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 12:59:27 26 4
gpt4 key购买 nike

我在为我的 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com