2013-03-12 83 views
2
public class BlendablePicture extends Picture { 
    public BlendablePicture(String filename) { 
     super(filename); 
    } 

    public void blendRectWithWhite(int xMin, int yMin, int xMax, int yMax, 
      double a) { 
     int x; 
     x = xMin; 
     while (x <= xMax) { 
      int y; 
      y = yMin; 
      while (y <= yMax) { 
       Pixel refPix = this.getPixel(x, y); 
       refPix.setRed((int) Math.round(refPix.getRed() * (1.0 + a))); 
       refPix.setGreen((int) Math.round(refPix.getGreen() * (1.0 + a))); 
       refPix.setBlue((int) Math.round(refPix.getBlue() * (1.0 + a))); 

       y = y + 1; 
      } 
     } 
    } 
} 

我需要將白色與像素混合,但相反,此代碼只是使得更亮!它需要像這樣:與白色混合圖片

Blended White - Illustrated

與此代碼的任何幫助,將不勝感激!

+1

「我需要將白色與像素混合在一起,但是這個代碼只是使亮度變得更亮!」嗯,什麼? – djechlin 2013-03-12 22:22:41

+0

我在那裏的方法「blendRectWithWhite」的代碼只是加強了像素顏色。我需要以某種方式將白色(255,255,255)與圖像混合。 – Alex 2013-03-12 22:25:00

回答

3

而不是

refPix.setRed ((int) Math.round (refPix.getRed() * (1.0+ a)));

試着這麼做

refPix.setRed ((int) Math.round (refPix.getRed()*(1.0-a)+255*a));

當a = 1.0,你會得到[R * 0.0 + 255 * 1.0 = 255

當a = 0.0,得到R * 1.0 + 255 * 0.0 = R

當a = 0.5時,你得到R * 0.5 + 255 * 0.5(半個)

這適用於任何顏色不只是白色,你只需要用紅色,綠色和藍色代替255的顏色你想與它混合的顏色,你可以得到RGB平均混合。

+0

(必填)是的,但是,它會混合? – Voldemort 2013-03-13 01:02:58

+1

@Omega是的,它融合在一起 – Patashu 2013-03-13 01:04:05