Here you can find the source of buildColorStatisticsOfImage(BufferedImage image)
Parameter | Description |
---|---|
image | The image to operate on |
private static Map<Integer, Integer> buildColorStatisticsOfImage(BufferedImage image)
//package com.java2s; //License from project: Open Source License import java.awt.image.BufferedImage; import java.util.HashMap; import java.util.Map; public class Main { /**//ww w. jav a 2 s . c o m * Builds a statistical map with all found colors as keys within a given * image. The values of the map represent the amount pixels found in the * key-colour. * * @param image * The image to operate on * @return A Map with <colorcode, amount> */ private static Map<Integer, Integer> buildColorStatisticsOfImage(BufferedImage image) { Map<Integer, Integer> colorStatistics = new HashMap<Integer, Integer>(); for (int i = 0; i < image.getWidth(); i++) { for (int j = 0; j < image.getHeight(); j++) { int rgb = image.getRGB(i, j); Integer counter = (Integer) colorStatistics.get(rgb); if (counter == null) { counter = 0; } counter++; colorStatistics.put(new Integer(rgb), counter); } } return colorStatistics; } }