Here you can find the source of makeTarget(BufferedImage image, int x, int y, int width, int height)
public static int[][] makeTarget(BufferedImage image, int x, int y, int width, int height)
//package com.java2s; //License from project: Apache License import java.awt.image.BufferedImage; public class Main { public static int[][] makeTarget(BufferedImage image, int x, int y, int width, int height) { int[][] target = new int[height][width]; for (int i = 0; i < height; ++i) { for (int j = 0; j < width; ++j) { int argb = image.getRGB(j + x, i + y); int a = (argb >> 24) & 0xFF; int r = (argb >> 16) & 0xFF; int g = (argb >> 8) & 0xFF; int b = argb & 0xFF; if (a == 0) { target[i][j] = -1;//from w w w . j ava2 s . co m } else { target[i][j] = ((299 * r + 587 * g + 114 * b) + 500) / 1000; } } } return target; } }