public static BufferedImage clip(BufferedImage src, int x, int y, int w, int h) {
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        BufferedImage work = null;
        
        try {
            GraphicsDevice screen = ge.getDefaultScreenDevice();
            GraphicsConfiguration gc = screen.getDefaultConfiguration();
            work = gc.createCompatibleImage(w, h, Transparency.BITMASK);
        } catch (Exception e) {
            System.out.println("Exception in BitmapFactory_Clip = " + e);
        }
        
        if (work == null) {
            work = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
        }
        
        int[] pixels = new int[w * h];
        src.getRGB(x, y, w, h, pixels, 0, w);
        work.setRGB(0, 0, w, h, pixels, 0, w);
        
        return work;
    }