Java tutorial
//package com.java2s; //License from project: Apache License import android.graphics.Bitmap; import android.os.Build; public class Main { public static int[] getPixelsFromBitmap(Bitmap bm, int x, int y, int width, int height) { int[] pixels = new int[width * height]; int tSize = byteSizeOf(bm); int size = width * height; int tWidth = bm.getWidth(); int tHeight = bm.getHeight(); int a = x; int b = y; int j = 0; for (int i = a + b * tWidth; i < size; i++) { if (a == x + width) { a = x; b++; } pixels[j++] = bm.getPixel(a, b); a++; } return pixels; } /** * returns the bytesize of the give bitmap */ public static int byteSizeOf(Bitmap bitmap) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { return bitmap.getAllocationByteCount(); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) { return bitmap.getByteCount(); } else { return bitmap.getRowBytes() * bitmap.getHeight(); } } }