2013-03-15 76 views
1

我想縮放一個像素的顏色組件。爲此,我正在創建一個新的像素,其中每個顏色分量都是原始值*該顏色的縮放係數。結果像素的值必須在0 <= color <= 255的範圍內。Java中的顏色縮放

這是我到目前爲止

public class ColorScale implements Transformer { 
    /* This part creates a transformer that scales the color in each pixel by the following factors 
     parameter r0 = red factor 
     parameter b0 = blue factor 
     parameter g0 = green factor 
    */ 

    public ColorScale(double r0, double g0, double b0) { 
     // need guidance as what to do here 
    } 

    public Pixel transformPixel(pixel p) { 
     return p; 
    } 
} 

更多信息做的是在這裏:http://www.seas.upenn.edu/~cis120/current/hw/hw07/javadoc/ColorScale.html

我是新來的Java,所以我只需要指導,在ColorScale功能做什麼。

+0

我認爲這是作業的意義。您需要弄清楚如何從給定的像素中獲取紅色/藍色/綠色值。然後,將每個值乘以它的因子。然後,您必須使用這些值創建一個新的Pixel對象,並從您的方法返回Pixel。 – camickr 2013-03-15 03:07:02

+0

所以基本上我離開transformPixel原樣?我只需要修改ColorScale,對吧? – user1993381 2013-03-15 03:26:00

+0

No. transformPixel()是您根據3個因素進行所有計算以將像素從一種顏色轉換爲另一種顏色的位置。 – camickr 2013-03-15 03:55:22

回答

3

從您提供的JavaDoc中,ColorScaleTransformer實現之一。

從您的代碼段:

public ColorScale(double r0, double g0, double b0) { 
    // need guidance as what to do here 
} 

這是構造。您正在創建一個instance的特定實現的像素Transformer(在這種情況下,ColorScale)。

構造函數應該簡單地設置的內部狀態,然後將它設置爲通過契約方法transformPixel來轉換像素。

換句話說,

public ColorScale(double r0, double g0, double b0) { 
    // Set internal state fields. 
    this.r0 = r0; 
    this.g0 = g0; 
    this.b0 = b0; 
}