To calculate the average color you have to calculate each a-,r-,g-,b-value seperately
I changed my code and it works pretty good now.
public static Bitmap downscaleBitmap(Bitmap src, int targetWidth, int targetHeight, int off){
float r = (src.getWidth()-off)/(float)targetWidth;
float s = (src.getHeight()-off)/(float)targetHeight;
Bitmap target = Bitmap.createBitmap(Math.round(src.getWidth()/r), Math.round(src.getHeight()/s), Config.ARGB_8888);
r = src.getWidth()/(float)target.getWidth();
s = src.getHeight()/(float)target.getHeight();
int argb;
int red;
int green;
int blue;
int alpha;
float wx;
float wy;
float n;
for(int i=0;i<target.getWidth();++i){
for(int j=0;j<target.getHeight();++j){
red = 0;
green = 0;
blue = 0;
alpha = 0;
n=0;
for(int k =(int)(i*r);k<roundUp((i+1)*r);++k){
if(k<i*r){
wx = k-i*r+1;
}else{
if(k+1>(i+1)*r)
wx = (i+1)*r-k;
else
wx = 1;
}
for(int l=(int)(j*s);l<roundUp((j+1)*s);++l){
if(l<j*s){
wy = l-j*s+1;
}else{
if(l+1>(j+1)*s)
wy = (j+1)*s-l;
else
wy = 1;
}
n+=wy*wx;
argb=src.getPixel(k, l);
red += wx*wy*Color.red(argb);
green += wx*wy*Color.green(argb);
blue += wx*wy*Color.blue(argb);
alpha += wx*wy*Color.alpha(argb);
}
}
target.setPixel(i, j, Color.argb((int)(alpha/n), (int)(red/n), (int)(green/n), (int)(blue/n)));
}
}
return target;
}