主要是操作下面的工具类


public class GraphicsUtil {

   public static final int SHIFT_RED_TO_GREEN = 0;

   public static final int SHIFT_RED_TO_BLUE = 1;

   public static final int SHIFT_GREEN_TO_BLUE = 2;

   public static final int SHIFT_GREEN_TO_RED = 3;

JAVA手机网[www.cnjm.net]

   public static final int SHIFT_BLUE_TO_RED = 4;

   public static final int SHIFT_BLUE_TO_GREEN = 5;

   public static int[] flipImageColor(Image source, int shiftType) {
       // we start by getting the image data into an int array - the number
       // of 32-bit ints is equal to the width multiplied by the height
       int[] rgbData = new int[(source.getWidth() * source.getHeight())];
JAVA手机网[www.cnjm.net]
       source.getRGB(rgbData, 0, source.getWidth(), 0, 0, source.getWidth(),
               source.getHeight());

       // now go through every pixel and adjust it's color
       for (int i = 0; i < rgbData.length; i++) {
           int p = rgbData[i];

           // split out the different byte components of the pixel by
           // applying
           // a mask so we only get what we need, then shift it to make it
           // a normal number we can play around with
           int a = ((p & 0xff000000) >> 24);
JAVA手机网[www.cnjm.net]
           int r = ((p & 0x00ff0000) >> 16);
JAVA手机网[www.cnjm.net]
           int g = ((p & 0x0000ff00) >> 8);
           int b = ((p & 0x000000ff) >> 0);

           int ba = a, br = r, bb = b, bg = g; // backup copies
JAVA手机网[www.cnjm.net]

           // flip the colors around according to the operation required
           switch (shiftType) {
           case SHIFT_RED_TO_GREEN:
               g = r;
JAVA手机网[www.cnjm.net]
               r = bg;
               break;
JAVA手机网[www.cnjm.net]
           case SHIFT_RED_TO_BLUE:
               b = r;
               r = bb;
               break;
           case SHIFT_GREEN_TO_BLUE:
               g = b;
JAVA手机网[www.cnjm.net]
               b = bg;
               break;
           case SHIFT_GREEN_TO_RED:
               g = r;
               r = bg;
               break;
           case SHIFT_BLUE_TO_RED:
               b = r;
JAVA手机网[www.cnjm.net]
               r = bb;
               break;
           case SHIFT_BLUE_TO_GREEN:
               b = g;
               g = bb;
               break;
           }

           // shift all our values back in
           rgbData[i] = (a << 24) | (r << 16) | (g << 8) | b;
       }

       return rgbData;
   }

}

调用:

int[] targetImage= GraphicsUtil.flipImageColor(srcImage, GraphicsUtil.SHIFT_RED_TO_BLUE);

g.drawRGB(targetImage,0,srcImage.getWidth(), 30, srcImage.getHeight() + 40, srcImage.getWidth(),srcImage.getHeight(), true);