public static ColorRgba getWeightedColor ( ImageBuffer surface , int sx , int sy , int width , int height ) { Check . notNull ( surface ) ; int r = 0 ; int g = 0 ; int b = 0 ; int count = 0 ; for ( int x = 0 ; x < width ; x ++ ) { for ( int y = 0 ; y < height ; y ++ ) { final ColorRgba color = new ColorRgba ( surface . getRgb ( sx + x , sy + y ) ) ; if ( color . getAlpha ( ) > 0 ) { r += color . getRed ( ) ; g += color . getGreen ( ) ; b += color . getBlue ( ) ; count ++ ; } } } if ( count == 0 ) { return ColorRgba . TRANSPARENT ; } return new ColorRgba ( ( int ) Math . floor ( r / ( double ) count ) , ( int ) Math . floor ( g / ( double ) count ) , ( int ) Math . floor ( b / ( double ) count ) ) ; }
Get the weighted color of an area .