日期:2014-05-20 浏览次数:20775 次
public class PalettedImage {
public Image getPalettedImage(byte[] data, int[] originalColors,
int[] palettedColors) {
byte[] tempData = new byte[data.length];
System.arraycopy(data, 0, tempData, 0, data.length);
Image img = null;
int[] parameter = { 0, 0, 0 };
analyze(tempData, parameter);
for (int i = 0; i < originalColors.length; i++) {
replaceColor(tempData, parameter, originalColors+,
palettedColors+);
}
fillData(tempData, parameter);
try {
img = Image.createImage(tempData, 0, data.length);
} catch (Exception e) {
System.out.println("getPalettedImage && " + e.toString());
}
return img;
}
private void analyze(byte[] data, int[] para) {
int offset = 8;
int chunkLen = 0;
while (data[offset + 4] != 0x50
------解决方案--------------------
data[offset + 5] != 0x4c
------解决方案--------------------
data[offset + 6] != 0x54
------解决方案--------------------
data[offset + 7] != 0x45) {
chunkLen = readInt(data, offset);
offset += (4 + 4 + chunkLen + 4);
}
chunkLen = readInt(data, offset);
para[2] = chunkLen / 3;
para[0] = offset + 8;
para[1] = offset + 8 + chunkLen;