2014-05-13 148 views
0

我遇到了這個任務的問題,我必須爲我的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(); 
    } 
} 
+0

什麼是編譯時錯誤? –

+0

在你的例子中,'backgroundDelete'和'backgroundImage'似乎沒有被初始化。這是你真正使用的課程嗎? –

回答

1

有幾件事情看起來像他們缺少。首先,您是導入Color和Pixel類,還是將它們包含在與ChromaKey類相同的包中?其次,您需要將backgroundImage和backgroundDelete定義爲一個類變量,以便在您的void chromaKey()方法中調用它(注意「private Picture backgroundDelete;」我添加的行,以及您的構造函數中的賦值):

公共類色度 {

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

}

+0

是的,我確實有我需要導入的所有東西[彩色/像素],添加你的建議後,我避免了編譯錯誤,程序給了我想要的結果! –

相關問題