This site requires JavaScript, please enable it in your browser!
Greenfoot back
Mux
Mux wrote ...

2012/12/1

getColorAt() doesn't work out

Mux Mux

2012/12/1

#
I got the code like this:
Color c = getColorAt(getWidth()-1,getHeight()-1);
        float[] colorValue = {c.getRed(),c.getGreen(),c.getBlue()}; 
the bugg report say its a null pointerExeption in the first line.
Color c = getColorAt(getWidth(),getHeight());
        float[] colorValue = {c.getRed(),c.getGreen(),c.getBlue()}; 
like this it say the x-Coordinate is 600 but has to be lower than 600. But the "-1" doesen't work so the problem must be something else. EDIT: what i want is to get the color of the pixel in the right bottom. First guess was that the hole thing fails in the constructer bur even in the act-cycle it doesent work.
Gevater_Tod4711 Gevater_Tod4711

2012/12/1

#
are you shure that the bugg is in this lines? because as I tried this there was no exception.
Mux Mux

2012/12/1

#
java.lang.IndexOutOfBoundsException: The x-coordinate is: 600. It must be smaller than: 600 at greenfoot.World.ensureWithinXBounds(World.java:841) at greenfoot.World.getColorAt(World.java:235) at world.createCoordinateSystem(world.java:135) the act thing :
public void act()
    {
        // creates the first coordinate system
        if(existingCoorSys == false)
        {
            createCoordinateSystem(-getWidth()/2, getWidth()/2, 10, 
                   -getHeight()/2, getHeight()/2, 10);
        }
       
        
        // updates the background 
        if( changelogChange == true)
        {
            updateBackground();
        }
    }
So this is the bugg and the hole method looks like this :
boolean existingCoorSys = false;
    /**
     *  creates a variable coordinate system 
     */
    public void createCoordinateSystem
                    (float xMin, float xMax,float xScale,
                     float yMin, float yMax,float yScale)

        if(changelogStore[getWidth()][getHeight()][1] == 
                       changelog[getWidth()][getHeight()][1])
        {
            Color c = getColorAt(getWidth(),getHeight());
            float[] colorValue = {c.getRed(),c.getGreen(),c.getBlue()}; 
            changeChangelog(getWidth(),getHeight(),
        (int)colorValue[0],(int)colorValue[1],(int)colorValue[2]);
        }
        existingCoorSys = true;
MatheMagician MatheMagician

2012/12/1

#
You need to leave in the -1 part or it will not work. I do not know why you would be getting an error otherwise.
Mux Mux

2012/12/1

#
ok it does work with the -1 propably but i get the mistake anyway. It must be somthing else. but thx for the help.
Mux Mux

2012/12/1

#
ok is there any other simpel way to get the color of a certain pixel. In this case the pixel in the right bottom corner?
MatheMagician MatheMagician

2012/12/1

#
No, this is as simple as it gets. I do not think it is the getColorAt method that is getting the error, though, since your code is working perfectly for me.
danpost danpost

2012/12/1

#
You need a GreenfootImage to use the getColorAt method on:
GreenfootImage image = getImage();
image.getColorAt(image.getWidth()-1, image.getHeight()-1);
Mux Mux

2012/12/1

#
Thanks for all the help i got the problem fixed now.
You need to login to post a reply.