byte[] data = ((DataBufferByte) buffImage.getRaster().getDataBuffer()).getData(); switch (buffImage.getType()) { case BufferedImage.TYPE_4BYTE_ABGR: convertFromARGBToBGRA(data);break; case BufferedImage.TYPE_3BYTE_BGR: convertFromBGRToRGB(data); break; default: System.out.println("Unknown type:"+buffImage.getType()); break; } //February 2nd, 2011: Fix for JAVA 1.6 thanks to sonicWonder for the fix private static void convertFromARGBToBGRA(final byte[] data) { for (int i = 0; i < data.length; i += 4) { data[i] ^= data[i + 3]; data[i+3] ^= data[i]; data[i] ^= data[i + 3]; data[i + 1] ^= data[i + 2]; data[i + 2] ^= data[i + 1]; data[i + 1] ^= data[i + 2]; } } private static void convertFromBGRToRGB(final byte[] data) { for (int i = 0; i < data.length; i += 3) { // A small optimisation data[i] ^= data[i + 2]; data[i + 2 ] ^= data[i ]; data[i] ^= data[i + 2]; } } //End February 2nd, 2011: Fix for JAVA 1.6 thanks to sonicWonder for the fix