Android examples for Graphics:Bitmap Color
has Color On Rect from Bitmap
//package com.java2s; import android.graphics.Bitmap; import android.graphics.Rect; public class Main { public static int hasColorOnRect(Bitmap src, Rect serchRect, int inputColor) { int width = serchRect.width(); int height = serchRect.height(); if (width == 0 || height == 0) return inputColor; int color = inputColor; if (width == 1 && height == 1) { color = src.getPixel(serchRect.left, serchRect.top); return color != inputColor ? color : inputColor; }/*ww w .j av a 2s . com*/ if (width == 1 && height > 1) { for (int start = 0; start < height; ++start) { color = src.getPixel(serchRect.left, serchRect.top + start); if (color != inputColor) return color; } return inputColor; } if (width > 1 && height == 1) { for (int start = 0; start < width; ++start) { color = src.getPixel(serchRect.left + start, serchRect.top); if (color != inputColor) return color; } return inputColor; } if (width > 1 && height > 1) { for (int x = 0; x < width; ++x) { for (int y = 0; y < height; ++y) { // Log.d("getColorOnBitmap", String.format("current searchX = (%s) and searchY = (%s)" + // " x = (%s), y = (%s), Pixel Color = (%s)" // , serchRect.left + x, serchRect.top + y // , x, y // , Integer.toHexString(src.getPixel(serchRect.left + x, serchRect.top + y)))); color = src.getPixel(serchRect.left + x, serchRect.top + y); if (color != inputColor) return color; } } return inputColor; } return inputColor; } }