Java tutorial
//package com.java2s; //License from project: Apache License import android.graphics.Bitmap; import android.support.annotation.NonNull; public class Main { public static int[] getBitmapPixels(@NonNull Bitmap bitmap, int x, int y, int width, int height) { int[] pixels = new int[bitmap.getWidth() * bitmap.getHeight()]; bitmap.getPixels(pixels, 0, bitmap.getWidth(), x, y, width, height); final int[] subsetPixels = new int[width * height]; for (int row = 0; row < height; row++) { System.arraycopy(pixels, (row * bitmap.getWidth()), subsetPixels, row * width, width); } return subsetPixels; } }