All pastes #2046361 Raw Edit

Something

public text v1 · immutable
#2046361 ·published 2011-04-14 12:09 UTC
rendered paste body
	private int getMinOrMax(BufferedImage img, int x, int y, int[][] shape, boolean erote) {
		// Initializing min and max values
		int minimum = Integer.MAX_VALUE;
		int maximum = Integer.MIN_VALUE;
		// Getting dimension of the image
		int width = img.getWidth();
		int height = img.getHeight();
		for(int i = 0; i<widthShape; i++)
			for(int j = 0; j<heightShape; j++){
				if(shape[i][j]==1){
					// Getting the x and y coordinates of the pixel to check
					int checkX = (x-(widthShape/2))+i;
					int checkY = (y-(heightShape/2))+j;
					// Check for out of bounds
					if(checkX>=0 && checkX<width && checkY>=0 && checkY<height){
						int rgb = img.getRGB(checkX, checkY);
						if(erote){
							if(rgb<minimum)
								minimum = rgb;
						}
						else{
							if(rgb>maximum)
								maximum = rgb;
						}
					}
				}				
			}

		if(erote)
			return minimum;
		else
			return maximum;				
	}