2013-03-29 38 views
-1

嗨,我有一个项目,我需要将白色和黑色混合在一起。我有黑色的代码工作,但我似乎无法得到白色的工作。有人可以告诉我我做错了什么,我早些时候做了简单的白色工作,但它走开了,我真的不知道如何......谢谢!底部的图片结果有链接!与白色混合图片

import java.awt.Color; 
public class BlendingWithBlackAndWhite 
{ 
public static void main(String[] args) 

{ 
FileChooser.pickMediaPath(); 
BlendablePic pRef = new BlendablePic(FileChooser.pickAFile()); 
double a[]= new double[3]; 
a[0]=0.1; 
a[1]=0.3; 
a[2]=0.5; 
pRef.blendRectWithWhite(0, 920, 920, 920, a[0]+0.9); 
pRef.blendRectWithWhite(920, 920, 920, 1840, a[2]); 
pRef.blendRectWithWhite(1840, 920, 920, 2760, a[1]-0.3); 
pRef.blendRectWithBlack(0,0, 920, 920, a[1]); 
pRef.blendRectWithBlack(920,0, 1784, 920, a[0]); 
pRef.blendRectWithBlack(1785,0, 2600, 920, a[2]*-0.2); 
pRef.explore(); 
}} 

public class BlendablePic extends Picture{ 
public BlendablePic(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)+255*a)); 
    refPix.setGreen((int)Math.round(refPix.getGreen() * (1.0-a)+200*a)); 
    refPix.setBlue((int)Math.round(refPix.getBlue() * (1.0-a)+255*a)); 
    y= y+1; 
    } 
    x = x+1; 
} 
} 
public void blendRectWithBlack(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() * (0.2 +a)+0*a)); 
    refPix.setGreen((int)Math.round(refPix.getGreen() * (0.2 +a)+0*a)); 
    refPix.setBlue((int)Math.round(refPix.getBlue() * (0.2 +a)+0*a)); 

    y = y+1; 
} 
x = x+1; 
} 
}} 

第一image是我需要做的,第二个是我从上面的编码得到的。

+0

yoru错误是什么? – smk

+0

@smk没有错误,我会尽量找到链接到图片的方法,坚持下去。 – neech

+0

@smk是更好的? – neech

回答

0

只要看图片,你必须已经有混合算法,当混合成白色时,你实际上没有做任何事情。这意味着方法应该几乎完全相同,其中一个是“添加”颜色,另一个是“减去”颜色。当我看着你的方法,我看,这是基本上是正确的,但你改变了第二加数...

(1.0-a)+255*a 
(1.0-a)+200*a 
(1.0-a)+255*a 


(0.2 +a)+0*a 
(0.2 +a)+0*a 
(0.2 +a)+0*a 

当你乘0 *一个,你会得到0,所以你掺和正是0.2 +一个。我怀疑你的问题在这里...

+0

我想通了!我所有的编码都是正确的,除了我正在制作一个线条而不是一个盒子,所以我无法在我的照片上看到它! – neech