// now loop from srcY to srcY2 and add up the values for
// each channel
do
{
argb = tmpPixels[x + srcY * destW];
a += ((argb & 0xff000000) >> 24); // alpha channel
r += ((argb & 0x00ff0000) >> 16); // red channel
g += ((argb & 0x0000ff00) >> 8); // green channel
b += (argb & 0x000000ff); // blue channel
++count; // count the pixel
++srcY; // move on to the next pixel
} while (srcY <= srcY2
&& x + srcY * destW < tmpPixels.length);
// average out the channel values
a /= count;
a = (a > 255) ? 255 : a;
r /= count;
r = (r > 255) ? 255 : r;
g /= count;
g = (g > 255) ? 255 : g;
b /= count;
b = (b > 255) ? 255 : b;
// recreate color from the averaged channels and place it
// into the destination buffer
destPixels[x + destY * destW] = ((a << 24) | (r << 16)
| (g << 8) | b);
}
}
}
// return a new image created from the destination pixel buffer
return drawPixels(destPixels, destW, destH);
}
}
有兴趣的网友可以仔细研究一下。我准备了一个图片,然后写了一个测试的MIDlet。下面是效果对比。

