嗨,我有一个项目需要将白色和黑色与图片混合。我有黑色代码工作,但我似乎无法让白色工作。有人可以告诉我我做错了什么吗,我早些时候让白色工作过,但它消失了,我真的不知道如何......谢谢!底部有图片结果的链接!
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;
}
}}
第一张图片是我需要做的,第二张是我从上面的编码中得到的。