Here you can find the source of determineBackgroundColor(BufferedImage bim)
public static Color determineBackgroundColor(BufferedImage bim)
//package com.java2s; /******************************************************************************* * <copyright> Copyright 2014 by E-Government Innovation Center EGIZ, Graz, Austria </copyright> * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a * joint initiative of the Federal Chancellery Austria and Graz University of * Technology.//from ww w. j a v a 2s .c o m * * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by * the European Commission - subsequent versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: * http://www.osor.eu/eupl/ * * Unless required by applicable law or agreed to in writing, software * distributed under the Licence is distributed on an "AS IS" basis, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and * limitations under the Licence. * * This product combines work with different licenses. See the "NOTICE" text * file for details on the various modules and licenses. * The "NOTICE" text file is part of the distribution. Any derivative works * that you distribute must include a readable copy of the "NOTICE" text file. ******************************************************************************/ import java.awt.Color; import java.awt.image.BufferedImage; import java.util.HashMap; public class Main { public static Color determineBackgroundColor(BufferedImage bim) { int inset = 5;//px int pixelUpLeft = bim.getRGB(inset, inset); int pixelUpRight = bim.getRGB(bim.getWidth() - inset, inset); int pixelDownLeft = bim.getRGB(inset, bim.getHeight() - inset); int pixelDownRight = bim.getRGB(bim.getWidth() - inset, bim.getHeight() - inset); HashMap<Integer, Integer> stats = new HashMap<Integer, Integer>(); stats.put(pixelUpLeft, 0); stats.put(pixelUpRight, 0); stats.put(pixelDownLeft, 0); stats.put(pixelDownRight, 0); stats.put(pixelUpLeft, stats.get(pixelUpLeft) + 1); stats.put(pixelUpRight, stats.get(pixelUpRight) + 1); stats.put(pixelDownLeft, stats.get(pixelDownLeft) + 1); stats.put(pixelDownRight, stats.get(pixelDownRight) + 1); int bgValue = -1; int cnt = 0; for (int key : stats.keySet()) { if (stats.get(key) > cnt) { cnt = stats.get(key); bgValue = key; } } return new Color(bgValue); } }