【发布时间】:2014-04-02 21:42:08
【问题描述】:
这是我的代码的样子。我收到一条错误消息,提示“线程“主”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();
}
}
【问题讨论】:
-
错误来自哪一行?还有什么是w?如果 w
-
在
drawredstripe中,您使用x作为垂直坐标,y作为水平坐标。这对我来说似乎不对。
标签: java coordinates bounds