Java ByteBuffer Size collidesWithImage(BufferedImage image, int x, int y, int width, int height, boolean pixelPerfect)

Here you can find the source of collidesWithImage(BufferedImage image, int x, int y, int width, int height, boolean pixelPerfect)

Description

collides With Image

License

Open Source License

Declaration

public static boolean collidesWithImage(BufferedImage image, int x, int y, int width, int height,
            boolean pixelPerfect) 

Method Source Code


//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;
    }
}

Related

  1. calcSize(ByteBuffer buffer)
  2. check(ByteBuffer buffer, int size)
  3. checkBounds(BufferedImage image, int xStart, int yStart, int width, int height)
  4. checkBufferSize(ByteBuffer buf, int elementSize)
  5. chooseAppropriateTileSize(BufferedImage image)
  6. convolve(final BufferedImage image, float[] elements, int theWidth, int theHeight)
  7. cover(BufferedImage source, File to, Image cover, int width, int height, int sourceTop, int sourceLeft, int sourceWidth, int sourceHeight)
  8. cutAndScaleToRoundSquare(BufferedImage src, int size, int radius)
  9. cutAndScaleToSquare(BufferedImage src, int size)