Hello Guest

# How can i get the real color in 2d game?

• 1 Replies
• 3292 Views

• 1
##### How can i get the real color in 2d game?
« on: May 06, 2010, 03:53:46 »
How can i get the real color in 2d game
« Last Edit: May 06, 2010, 03:55:52 by adam_1212 »

#### wondersonic

• 40
##### Re: How can i get the real color in 2d game?
« Reply #1 on: May 06, 2010, 10:25:27 »
Hey, I see you tried the wonderful Propotyp project.

In fact, you just suffer from the correction of BUG http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6879279 from JDK 1.6.0_18.

Indeed they changed the type for PNG images so you have to convert back RGBA components.

For example, I do:

Code: [Select]
`buffImage = ImageIO.read(cl.getResource(path));final 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;                }...    private static void convertFromARGBToBGRA(final byte[] data) {        final int size = data.length;        for (int i = 0; i < size; i += 4) {            final int a = data[i] & 0x000000FF;            final int r = data[i + 1] & 0x000000FF;            final int g = data[i + 2] & 0x000000FF;            final int b = data[i + 3] & 0x000000FF;            data[i] = (byte) b;            data[i + 1] = (byte) g;            data[i + 2] = (byte) r;            data[i + 3] = (byte) a;        }    }    private static void convertFromBGRToRGB(final byte[] data) {        final int size = data.length;        for (int i = 0; i < size; i += 3) {            final int b = data[i] & 0xFF;            final int g = data[i + 1] & 0xFF;            final int r = data[i + 2] & 0xFF;            data[i] = (byte) r;            data[i + 1] = (byte) g;            data[i + 2] = (byte) b;        }    }`
WS
S.