显示图像的RGB编号的java
我需要显示所选图片中每个像素的所有RGB数字,每个数字用空格分隔,并在图片的每一行后使用println(break)。我已经找到并编写了返回所有RGB数字的代码,但我不知道如何在每行之后中断。这是我到目前为止的代码
public void getColor()
{
System.out.println("This picture's dimensions are: "+this.getWidth()+" by "+this.getHeight());
for (int row=0; row < this.getHeight(); row++) // gives the number of rows
{
for (int col=0; col < this.getWidth(); col++)// gives the number of columns
{
Pixel pix = this.getPixel(col,row);
System.out.print(pix.getRed()+" "+pix.getGreen()+" "+pix.getBlue()+" ");
} // end of inner loop
}// end of outer loop
} // end of method
# 1 楼答案
您需要将换行符放在最里面的for循环之外,因为您希望它在每行完成后运行
# 2 楼答案
将此项放在col循环之后:
系统。出来打印(System.getProperty(“line.separator”)
见本页: http://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html
# 3 楼答案
只要在内环和外环之间插入一条print语句,就可以在每一行的末尾添加一个换行符