title: Cropping an image using Java
body: <p>How to crop images in Java? I currently have this class for image manipulation.</p>
  
  <p>The main method with the run method:</p>
  
  <pre><code>public static void main(String[] args) {
      GameProject gp = new GameProject();
      gp.run();
  }
  
  public void run(){
      s = new Screen();
  
      try {
          DisplayMode dm = s.findFirstCompatibleMode(modes);
          s.setFullscreen(dm);
          Fonts f = new Fonts(); //Checks if certain fonts exsist, if not install them.
          Images i = new Images(); 
  
          try { 
              i.draw("H:\\Dropbox\\Dropbox\\GameProject\\src\\Resources\\brock.png", 200, 200);
              Thread.sleep(50000);
          } catch (Exception e) {}
      } finally {
          s.restoreScreen();
      }
  }
  </code></pre>
  
  <p><br>
  <em>Images</em> class:</p>
  
  <pre><code>package Handlers;
  
  import javax.swing.ImageIcon;
  import java.awt.*;
  
  /**
   *
   * @author Steven
   */
  public class Images {
  
      /**
       * @param args the command line arguments
       */
      private Screen s;  
  
      public void draw(String name, int x, int y) {   //Draws the image
          s = new Screen();
          Graphics2D g = s.getGraphics();
          draws(g, name, x, y, getWidth(name), getHeight(name));
      }   
  
      public void drawA(String name, int x, int y){   //Draws the image, allows for a more advanced image manipulation 
          s = new Screen();
          Graphics2D g = s.getGraphics();
          draws(g, name, x, y, getWidth(name), getHeight(name));
      }       
  
      public void draws(Graphics g, String name, int x, int y, int w, int h) {    //Draws and updates the screen
          s = new Screen();
          g.drawImage(new ImageIcon(name).getImage(), x, y, w, h, null);
          s.update();
      }
  
      public int getWidth(String name) {  //Gets the image width
          return new ImageIcon(name).getIconWidth();
      }
  
      public int getHeight(String name) { //Gets the images height
          return new ImageIcon(name).getIconHeight();
      }
  
  }
  </code></pre>
  
  <p><br>
  Any help would be appreciated.</p>