title: How to flip an image horizontally
body: <p>HiI was wondering how to flip and image horizontally, for a practce task I was given a code that reads an image, inverting it to an image indicating it's brightness from 0-5, I had to flip an image.</p>
  <p>This is my code of my reading an image and drawing it</p>
  <pre><code>public int[][] readImage(String url) throws IOException
  {
      // fetch the image
      BufferedImage img = ImageIO.read(new URL(url));
  
      // create the array to match the dimensions of the image
      int width = img.getWidth();
      int height = img.getHeight();
      int[][] imageArray = new int[width][height];
  
      // convert the pixels of the image into brightness values
      for (int x = 0; x &lt; width; x++)
      {
          for (int y = 0; y &lt; height; y++)
          {
              // get the pixel at (x,y) 
  
              int rgb = img.getRGB(x,y);
              Color c = new Color(rgb);
              int red = c.getRed();
              int green = c.getGreen();
              int blue = c.getBlue();
  
              // convert to greyscale
              float[] hsb = Color.RGBtoHSB(red, green, blue, null);                
              int brightness = (int)Math.round(hsb[2] * (PIXEL_CHARS.length - 1));
  
              imageArray[x][y] = brightness;
          }
      }
      return imageArray;
  }
  
  public void draw() throws IOException
  {
      int[][] array = readImage(&quot;http://sfpl.org/images/graphics/chicklets/google-small.png&quot;);
      for(int i=0; i&lt;array.length; i++)
      {
          for(int pic=0; pic&lt;array[i].length; pic++)
          {
              if(array[pic][i] == 0)
              {
                  System.out.print(&quot;X&quot;);
              }
              else if(array[pic][i] == 1)
              {
                  System.out.print(&quot;8&quot;);
              }
  
              else if(array[pic][i] == 2)
              {
                  System.out.print(&quot;0&quot;);
              }       
  
              else if(array[pic][i] == 3)
              {
                  System.out.print(&quot;:&quot;);
              }
  
              else if(array[pic][i] == 4)
              {
                  System.out.print(&quot;.&quot;);
              }
  
              else if (array[pic][i] == 5)
              {
                  System.out.print(&quot; &quot;);
              }
  
              else 
              {
                  System.out.print(&quot;error&quot;);
                  break;
              }   
  
          }
          System.out.println();
      }
  }    
  </code></pre>
  <p>and this is the code I tried to create to horizontally flip it,</p>
  <pre><code>void mirrorUpDown()
  {
      int[][] array = readImage(&quot;http://sfpl.org/images/graphics/chicklets/google-small.png&quot;);
      int i = 0;
  
      for (int x = 0; x &lt; array.length; x++)
      {
          for (int y = 0; y &lt; array[i].length; y++)
          {{
                  int temp = array[x][y]; 
                  array[x][y]= array[-x][y]; 
                  array[array[i].length-x][y]=temp;
              }
          }
      }
  
  }    
  </code></pre>
  <p>I get an error</p>
  <pre><code> unreported exception java.io.IException;
   must be caught or declared to be thrown
  </code></pre>