循环改变图片的像素值,请注意每一行使用一个颜色。
int []data = new int[fontImage.getWidth() * fontImage.getHeight()];
fontImage.getRGB(data,
0, fontImage.getWidth(), 0, 0, fontImage.getWidth(),
fontImage.getHeight());
int newColor = fontColor;
int r =
(fontColor & 0x00FF0000)>>16;
int g = (fontColor &
0x0000FF00)>>8;
int b = (fontColor & 0x000000FF);
int offsetR = r/fontImage.getHeight();
int offsetG =
g/fontImage.getHeight();
int offsetB = b/fontImage.getHeight();
for(int
i=0; i<data.length; i++){
if(data[i] != backgroundColor){
data[i] = newColor;
}
if(i%imageWidth == 0){ // subtract
each color on every row.
if(r>offsetR)
r -=
offsetR;
if(g>offsetG)
g -= offsetG;
if(b>offsetB)
b -= offsetB;
newColor = 0xFF000000; // make the pixel opaque.
newColor += (r<<16);
newColor += (g<<8);
newColor += b;
}
}