I've been having some problems getting a color at a specific pixel and am starting to believe there may be a bug. The image I'm using (bg1.png) is a transparent PNG with a solid black rectangle in the middle. It's original dimensions are 1440x900, but I'm scaling it to 800x500 to fit in my window. When I click on the image, it consistently prints "Color(1.0, 1.0, 1.0, 0.0)", no matter where I click. Here are some snippets:
Init:
Code:
public void init( GameContainer container ) throws SlickException
{
container.getGraphics().setBackground( Color.magenta );
input = container.getInput();
// Set up the first scene
background = (new Image( "assets/bg1.png" )).getScaledCopy( 800, 500 );
}
Render:
Code:
public void render( GameContainer container, Graphics g )
throws SlickException
{
background.draw( 0f, 0f );
}
Update:
Code:
public void update( GameContainer container, int delta )
throws SlickException
{
if( input.isMousePressed( Input.MOUSE_LEFT_BUTTON ) )
{
int x = input.getAbsoluteMouseX();
int y = input.getAbsoluteMouseY();
Color c = background.getColor( x, y );
// Test it out
System.out.println( c );
}
}
I think this is a bug with scaled images. I tested this without scaling the image, and it worked just fine.