【发布时间】:2016-03-08 19:57:01
【问题描述】:
我正在创建一个方法,该方法采用两个参数和 2 个索引,一个开始和一个结束,它采用正在编辑的图片的位置并将这些像素转换为不同的颜色。使用 while 循环来索引开始和结束。
我遇到的问题是我只有一小部分可以改变颜色:
不要介意一些被注释掉的代码。我尝试了一堆不同的东西。
public void negative(int start, int end)
{
Pixel[] pixelArray = this.getPixels(); //pixelarray index
Pixel pixel = null;
// int height = this.getHeight();
//int paintPoint = height / 2;
//int width = this.getWidth();
int i = 0;
int red, green, blue = 0;
// int x = 0;
Pixel topPixel = null;
Pixel bottomPixel = null;
//int startY;
//int startX;
int y = start;
int x = end;
//int count;
while( y < this.getHeight())
{
y++;
while (x < this.getWidth()) //loops through index
{
pixel = this.getPixel(x,y);
red = pixel.getRed();
green = pixel.getGreen();//collects color green
blue = pixel.getBlue();//collects color blue
Color negColor = new Color( 255 - red, 255 - green, 255 - blue);//sets new values of pixels
pixel.setColor(negColor);
x++;
//count = count + 1;
i++;//indexes continuing
}
}
}
【问题讨论】:
标签: java arrays indexing while-loop pixel