How to detect Pixel order RGBA vs ABGR

Hi,
the new java version 1.6.0_20 is coursing some troubles with my transparent images. The transparency is swapped and the pixels of a buffered image are in the order ABGR.
Before it was RGBA.

How can I determine the order?

Since I want to have the correct colors in all of the versions (at least the newer java versions)

I tried this:

public void findPixelChannelOrder(){
		BufferedImage image = FileController.getInstance().getImage("rsc/red.gif"); 
		int firstpixel = image.getRGB(0,0);
		int r = (firstpixel & 0xff000000) >> 16;
		int g = (firstpixel & 0x00ff0000) >> 16;
		int b = (firstpixel & 0x0000ff00) >> 16;
		int a = (firstpixel & 0x000000ff) >> 16;

		GUIController.getInstance().getConsole().print("r: "+r+" g: "+g+" b: "+b+" a: "+a);
		if (r == 255){
			EnvironmentController.getInstance().setRGBA(true);
		}else{
			if (a == 255){
				EnvironmentController.getInstance().setRGBA(false);
			}
		}
	}

but it is useless, had also some other configurations shifting in different direction etc but its not working.

I am stucked here.

PRoblem solved in a different way.

BufferedImage.getType();

match against BufferedImage.TYPE_{zillion types}

It’s plain easier to copy your image to a format you specify yourself:


public static BufferedImage copyAs(BufferedImage image, int type)
{
   BufferedImage copy = new BufferedImage(image.getWidth(), image.getHeight(), type);
   if(copy.getColorModel().hasAlpha())
      makeTransparant(copy);
   copy.getGraphics().drawImage(image, 0, 0, null);
   return copy;
}

public static void makeTransparant(BufferedImage img)
{
   Graphics2D g = img.createGraphics();
   g.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR, 0.0f));
   g.fillRect(0, 0, img.getWidth(), img.getHeight());
   g.dispose();
}

// usage:
myImage = copyAs(myImage, BufferedImage.TYPE_INT_RGBA);