/*
* http://blog.csdn.net/the3gwireless
*
* 图像反转的方法
*/

public static Image reverseRGB(Image image) {
// System.out.println("reverseRGB IN");
int width = image.getWidth();
int height = image.getHeight();
// 获得图像的ARGB数据,存储在rawInt里
int[] raw = null;
try {
raw = new int[width * height];
image.getRGB(raw, 0, width, 0, 0, width, height);
int len = raw.length;
// 开始循环,获得图像里每个像素的颜色,然后处理
for (int i = 0; i < len; i++) {
// 获得像素的颜色
int color = raw[i];
// System.out.println(Integer.toHexString(color));
// 获得alpha
int alpha = 0xFF;
// System.out.println(Integer.toHexString(alpha));
// 获得红色
int red = (color & 0x00FF0000) >> 16;
// System.out.println(Integer.toHexString(red));
// 获得绿色
int green = (color & 0x0000FF00) >> 8;
// System.out.println(Integer.toHexString(green));
// 获得蓝色
int blue = (color & 0x000000FF);
// System.out.println(Integer.toHexString(blue));
// 翻转颜色
red = 0xFF - red;
green = 0xFF - green;
blue = 0xFF - blue;
// 生成新颜色
// System.out.println(Integer.toHexString((alpha << 24)+ (red <<
// 16)+(green << 8)));
color = (alpha << 24) + (red << 16) + (green << 8) + blue;
// System.out.println(Integer.toHexString(color));
raw[i] = color;
}
// System.out.println("blendRGB OUT");
return Image.createRGBImage(raw, width, height, true);

} catch (Error e) {
// e.printStackTrace();
ImageAlbum.showAlert("图像尺寸太大,不能完成此操作.");
return image;
} catch (Exception e) {
e.printStackTrace();
return image;
} finally {
raw = null;
}
}