[英]Cannot find symbol compiler error
我在為Java編程類要做的這項作業時遇到問題。 我要做的是對具有純背景的圖像執行色度鍵技術。 更多信息可以在這里找到。 當我為方法放置兩個對象參數時,創建的方法就可以使用。 但是,當我將參數放入構造函數中,然后嘗試使用該方法時,出現編譯器錯誤。 我的課程在下面(我必須使用兩個不同的類,一個用於方法,一個用於測試)。 任何幫助將不勝感激,我是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;”行以及構造函數中的賦值):
公共類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();
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.