Я делаю задание по редактированию изображения в Java. Задание просит сделать код, изменяющий цвета изображения на 3 разных оттенка, и анимировать его, чтобы он был похож на GIF. Я выполнил задания, но каким-то образом, когда они меняются между оттенками, изображение теряет детали и пропускает только синий пустой цвет при третьем изменении оттенка. Я пытался добавить код, возвращающий значение цвета в источник, прежде чем менять следующий, но все же эта проблема возникает. Возможно, я неправильно понял код. Может ли кто-нибудь помочь мне с этим.
/* Assignment 3, Part 1 - Go Psychedelic! */
public class Assignment3Part1
{
//
public static void main(String [] args) throws InterruptedException
{
String filename;
if (args.length > 0) {
// got a filename passed into program as a parameter
// don't change this part of the code needed by TA for grading
filename = args[0];
System.out.println("Filename passed in: " + filename);
} else {
// ask user for a picture
filename = FileChooser.pickAFile();
System.out.println("User picked file: " + filename);
}
Picture pic = new Picture(filename); // Picture to modify
//
pic.show(); // Show the original picture
Thread.sleep(1000); // Pause for 1 second. You can pause for less if you like
// TODO: insert method call to tint your picture
pic.tintRed(50);
pic.repaint(); // Show the tinted picture
Thread.sleep(1000); // Pause for 1 second
// TODO: insert method call to tint your picture
pic.tintRed(-50);
pic.tintGreen(20);
pic.repaint(); // Show the tinted picture
Thread.sleep(1000); // Pause for 1 second
// TODO: insert method call to tint your picture
pic.tintGreen(0);
pic.tintBlue(10);
pic.repaint(); // Show the tinted picture
Thread.sleep(1000); // Pause for 1 second
} // End of main method
} // End of class
Коды для метода
public void tintRed(int percent)
{
Pixel[] pixelArray = this.getPixels();
Pixel pixel = null;
int value = 0;
int i = 0;
//loop through all the pixels in the array
while (i<pixelArray.length)
{
// get the current pixel
pixel = pixelArray[i];
// get the value
value = pixel.getRed();
// set the value to % of what it was
pixel.setRed((int)(value*percent));
// increment the index
i++;
}
}
То же самое для значений синего и зеленого