get Bitmap Pixels - Android Graphics

Android examples for Graphics:Bitmap Pixel

Description

get Bitmap Pixels

Demo Code


//package com.java2s;
import android.graphics.Bitmap;

public class Main {
    public static int[] getBitmapPixels(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);
        }//from w ww  . ja  v  a  2s  .  co m
        return subsetPixels;
    }
}

Related Tutorials