代码:
/**
* 图片转换
* @param content 原始图片信息
* @param type 类型,1 :中立角色 2 : 敌方 0 :自己
*/
public static void imgConvert(byte content[], int type){
try{
int pos = 33;
int relpos = 0;
relpos = ((content[pos] & 0xff) << 24 (content[pos + 1] & 0xff) << 16 (content[pos + 2] & 0xff) << 8 content[pos + 3] & 0xff) & -1;
pos += 4;
int newcolor = -1;
for(int idx = 0; idx < 4; idx++)
newcolor = pixelConvert(content[pos + idx], newcolor);
pos += 4;
boolean flag = true;
boolean flag1 = false;
boolean flag2 = false;
for(int idx = pos; idx < pos + relpos; idx += 3){
int b = content[idx] & 0xff;
int g = content[idx + 1] & 0xff;
int r = content[idx + 2] & 0xff;
if(r > b && r > g){
//绿色和蓝色互换,中立角色
if(type == 1){
int tmp = b;
b = g;
r = b;
g /= 2;
}
//转换为红色,敌人角色
else if (type == 2){
b = r;
g = r;
}
content[idx] = (byte)b;
content[idx + 1] = (byte)g;
content[idx + 2] = (byte)r;
}
newcolor = pixelConvert(content[idx], newcolor);
newcolor = pixelConvert(content[idx + 1], newcolor);
newcolor = pixelConvert(content[idx + 2], newcolor);
}
newcolor = ~newcolor;
int actpos = 41 + relpos;
content[actpos] = (byte)(newcolor >> 24);
content[actpos + 1] = (byte)(newcolor >> 16);
content[actpos + 2] = (byte)(newcolor >> 8);
content[actpos + 3] = (byte)newcolor;
}
catch(Exception e){}
}
/**
* 像素转换
* @param pixel 像素
* @param color 颜色值
* @return
*/
public static int pixelConvert(byte pixel, int color){
int tmp = pixel & 0xff;
color ^= tmp;
for(int idx = 0; idx < 8; idx++)
if((color & 1) != 0)
//土黄色
color = color >>> 1 ^ 0xedb88320;
else
color >>>= 1;
return color;
}