Вот как выглядит мой код. Я получаю сообщение об ошибке «Исключение в потоке «основной» java.lang.arrayIndexOutofBoundsException: координата выходит за пределы!» Я не знаю, что это значит и как это исправить, поэтому любая помощь приветствуется.
import java.awt.Color;
public class Assignment9 {
/**
* @param args
* @return
*/
public static void removeBlue(Picture pic){
Color cPic = pic.get(100,100);
//remove blue color pane from image, set blue weight to 0
int h = pic.height();
int w = pic.width();
System.out.println(cPic);
//^this shows the red, green, and blue weights
int b = cPic.getBlue();
int r = cPic.getRed();
int g = cPic.getGreen();
System.out.println("r=" +r +"g="+g+"b="+b);
pic.setColor(w, h, r, g, 0);
for(int x=0; x<w ; x++){
//need to set color
pic.setColor(w, h, r, g, 0);}
}
public static void drawredStripe(Picture pic){
//draw a red vertical stripe that is 200 pixels wide through the middle of the image
Color cPic = pic.get(100,100);
int h = pic.height();
int w = pic.width();
int b = cPic.getBlue();
int r = cPic.getRed();
int g = cPic.getGreen();
for(int x=0; x<h ; x++){
for (int y = (w/2)-100; y <(w/2)+100; y++){
//need to set color
pic.setColor(x, y, r, 0, 0);
}
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Picture dolphin= new Picture("dolphin_swimming.jpg");
removeBlue(dolphin);
dolphin.show();
drawredStripe(dolphin);
dolphin.show();
}
}
drawredstripe
вы используетеx
в качестве вертикальной координаты иy
в качестве горизонтальной координаты. Мне это не кажется правильным. - person Dawood ibn Kareem   schedule 03.04.2014