Java tutorial
//package com.java2s; import android.graphics.Bitmap; import android.graphics.Rect; public class Main { public static int getColorOnBitmap(Bitmap src, Rect serchRect, int defaultColor) { int width = serchRect.width(); int height = serchRect.height(); // Log.d("getColorOnBitmap", String.format("bitmap width = (%s), height = (%s), Rect = (%s)", src.getWidth() // , src.getHeight(), serchRect.toString())); if (width == 0 || height == 0) return defaultColor; if (width == 1 && height == 1) { return src.getPixel(serchRect.left, serchRect.top); } if (width == 1 && height > 1) { int colorMerge = 0xffffffff; for (int start = 0; start < height; ++start) { colorMerge = colorMerge & src.getPixel(serchRect.left, serchRect.top + start); } return colorMerge; } if (width > 1 && height == 1) { int colorMerge = 0xffffffff; for (int start = 0; start < width; ++start) { colorMerge = colorMerge & src.getPixel(serchRect.left + start, serchRect.top); } return colorMerge; } if (width > 1 && height > 1) { int colorMerge = 0xffffffff; for (int x = 0; x < width; ++x) { for (int y = 0; y < height; ++y) { colorMerge = colorMerge & src.getPixel(serchRect.left + x, serchRect.top + y); } } return colorMerge; } return defaultColor; } }