Android examples for Graphics:Bitmap Color
Get Bitmap size Trimmable Top by color
//package com.java2s; import android.graphics.Bitmap; import android.graphics.Color; public class Main { private static final double FUZZ = 0.1; public static final float sizeTrimmableTop(Bitmap b) { for (int y = 0; y < b.getHeight() - 1; y++) { for (int x = 0; x < b.getWidth() - 1; x++) if (colorDistance(b.getPixel(x, y), b.getPixel(x + 1, y)) > FUZZ) return (float) y / b.getHeight(); if (colorDistance(b.getPixel(0, y), b.getPixel(0, y + 1)) > FUZZ) return (float) y / b.getHeight(); }// w w w .jav a 2 s . c om return 0; } private static final double colorDistance(int color1, int color2) { int redDistance = Color.red(color1) - Color.red(color2); int greenDistance = Color.green(color1) - Color.green(color2); int blueDistance = Color.blue(color1) - Color.blue(color2); double distance = Math.sqrt(redDistance * redDistance + greenDistance * greenDistance + blueDistance * blueDistance); return distance / 256.; } }