Android examples for Graphics:Bitmap Color
Get Bitmap size Trimmable Bottom 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 sizeTrimmableBottom(Bitmap b) { for (int y = 1; y < b.getHeight(); y++) { for (int x = 0; x < b.getWidth() - 1; x++) if (colorDistance(b.getPixel(x, b.getHeight() - y), b.getPixel(x + 1, b.getHeight() - y)) > FUZZ) return (float) (y - 1) / b.getHeight(); if (colorDistance(b.getPixel(0, b.getHeight() - y), b.getPixel(0, b.getHeight() - y - 1)) > FUZZ) return (float) (y - 1) / b.getHeight(); }/*from ww w .ja v a2 s . co m*/ 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.; } }