Here you can find the source of loadImage(String i, int x, int imageWidth, int imageHeight)
public static BufferedImage loadImage(String i, int x, int imageWidth, int imageHeight)
//package com.java2s; //License from project: Open Source License import javax.imageio.ImageIO; import java.awt.*; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; public class Main { public static BufferedImage loadImage(String i, int x, int imageWidth, int imageHeight) { try {// w w w . j av a 2s . c om GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gs = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gs.getDefaultConfiguration(); BufferedImage tempBuff = ImageIO.read(new File(i)); BufferedImage a = gc.createCompatibleImage(imageWidth, imageHeight, Transparency.TRANSLUCENT); Graphics tempG = a.getGraphics(); tempG.drawImage(tempBuff.getSubimage(x, 0, imageWidth, imageHeight), 0, 0, null); tempG.dispose(); return a; } catch (IOException ioexception) { return null; } } }