Get pixel color from Image *resolved*

Hey folks,
im new here and i guess this is kinda a newbe question, but i tried searching it and couldnt find anything usefull so here goes:

I’m making an isometric strategy game, and now i need to check whether the mouse is over a transparent part of a sprite or not.
The sprites are loaded in ImageIcon objects, and stored in gifs with a transparent pallete, which i sat to regular pink (255,0,255).
Any sweet prewritten code i can use?
I’d just love a getRed() getBlue() style solution =)

Well, i’m so far enjoying java, and i hope i can contribute on this forum.
Cheers!

  • Jonas

Use java.awt.image.BufferedImage instead of ImageIcon and use getRGB(int x, int y) to get the color.

getRGB returns an int… how can you determine whether or not that int represents transparentcy? do you have to use bitwise operators to extract byte values into individual ints?

I’m new to bufferedImage, and for how long I’ve been trying to figure it out in the API docs, i’ve had to put it off while I work on another feature in hopes that I’ll understand a bit more about java so as to use bufferedImage when I return to it.
So how exactly can one determine if an x,y coord is transparent on a bi?

The transparency, also called alpha, is stored in the bits [24, 31] of the int returned. Just shift it like this: “int alpha = (color >>> 24)”, and you’ve got the transparency in the [0, 7] bits. 256 values, where 0 is transparent and 255 is opaque.

Try searcing the forum or google for more information. It’s been explained a bunch of times before.

that worked sweet =)
Thanks!

me too, thanks a lot bro!