Java 显示图像的RGB编号

Java 显示图像的RGB编号,java,image,rgb,pixels,Java,Image,Rgb,Pixels,我需要显示所选图片中每个像素的所有RGB数字,每个数字用空格分隔,并在图片的每一行后使用println(break)。我已经找到并编写了返回所有RGB数字的代码,但我不知道如何在每行之后中断。这是我到目前为止的代码 public void getColor() { System.out.println("This picture's dimensions are: "+this.getWidth()+" by "+this.getHeight()); for (int row=0; r

我需要显示所选图片中每个像素的所有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
public void getColor()
{
System.out.println(“这张图片的尺寸是:“+This.getWidth()+”乘以“+This.getHeight()”);
for(int row=0;row
只要在内环和外环之间插入一条打印语句,在每行末尾添加一个换行符即可

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
     System.out.print("\n"); //added line break to end of line.
   }// end of outer loop
} // end of method
public void getColor()
{
System.out.println(“这张图片的尺寸是:“+This.getWidth()+”乘以“+This.getHeight()”);
for(int row=0;row
将其放在col循环之后:

System.out.print(System.getProperty(“line.separator”)

见本页:

您需要将换行符放在最里面的for循环之外,因为您希望它在每行完成后运行

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

    //After this ^^^ for loop runs, you've gone over the whole row.
    System.out.println();
   }// end of outer loop
} // end of method
public void getColor()
{
System.out.println(“这张图片的尺寸是:“+This.getWidth()+”乘以“+This.getHeight()”);
for(int row=0;row
最好改用
System.out.println()
——主要是因为这就是它的本意。是的,尽管其他人已经用该解决方案给出了答案。因此,我觉得最好还是把我的作为一个替代品,因为它有很多其他人阅读的应用程序,将来可能会用到。啊,很公平。我没看到那个。