Here you can find the source of collidesWithImage(BufferedImage image, int x, int y, int width, int height, boolean pixelPerfect)
public static boolean collidesWithImage(BufferedImage image, int x, int y, int width, int height, boolean pixelPerfect)
//package com.java2s; //License from project: Open Source License import java.awt.image.BufferedImage; public class Main { public static boolean collidesWithImage(BufferedImage image, int x, int y, int width, int height, boolean pixelPerfect) { if (x > 0 && x < width) { if (y > 0 && y < height) { if (pixelPerfect == true) { double widthGrad = ((double) image.getWidth()) / ((double) width); double heightGrad = ((double) image.getHeight()) / ((double) height); int pixelX = (int) (((double) x) * widthGrad); int pixelY = (int) (((double) y) * heightGrad); int pixel = image.getRGB(pixelX, pixelY); int alpha = (pixel >> 24) & 0xFF; if (alpha == 0) { return false; } else { return true; }/*from w w w .ja va 2 s.c o m*/ } else { return true; } } } return false; } }