Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

import android.graphics.Color;

public class Main {
    /**
     * Return histogram of grayscaled image
     */
    public static int[] getHistogram(Bitmap bmp) {
        int[] histogram = new int[256];
        int width = bmp.getWidth();
        int height = bmp.getHeight();
        int[] pixels = new int[width * height];
        bmp.getPixels(pixels, 0, width, 0, 0, width, height);

        for (int i = 0; i < width * height; i++) {
            int c = Color.red(pixels[i]);
            histogram[c] += 1;
        }

        return histogram;
    }
}