Skip to content

Instantly share code, notes, and snippets.

@httnn
httnn / gist:a6ab15cbba9c82a5065d
Created April 9, 2015 16:28
Calculate average color of Android Bitmap
/*
pixelSpacing tells how many pixels to skip each pixel.
If pixelSpacing > 1: the average color is an estimate, but higher values mean better performance
If pixelSpacing == 1: the average color will be the real average
If pixelSpacing < 1: the method will most likely crash (don't use values below 1)
*/
public int calculateAverageColor(android.graphics.Bitmap bitmap, int pixelSpacing) {
int R = 0; int G = 0; int B = 0;
int height = bitmap.getHeight();
int width = bitmap.getWidth();