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

2023/3/6

Darkening and image

LucarioCodes LucarioCodes

2023/3/6

#
for (int x = 0; x < getWidth(); x++)
        {
            for (int y = 0; y < getHeight(); y++)
            {
                GreenfootImage bg = getBackground();
                Color beep = bg.getColorAt(x,y);
                Color darken = Color darken;                
            }
        }
Im trying to darken an image in an older verson of greenfoot, but the image won't darken as it keeps giving me errors. Can anyone help?
danpost danpost

2023/3/7

#
LucarioCodes wrote...
<< Code Omitted >> Im trying to darken an image in an older verson of greenfoot, but the image won't darken as it keeps giving me errors. Can anyone help?
First off, you get a color from the image and place it in a variable called beep; but, the variable is not used at any later time. Maybe you mean the following at line 7:
Color darken = beep.darker();
Secondly, changing the color held by the variable (as done in the code line I provided above) does not change the color in the image the color was taken from. You will need to set the color to the image after the change:
bg.setColorAt(x, y, darken);
LucarioCodes LucarioCodes

2023/3/7

#
Thanks for the help! Can't believe I missed that!
You need to login to post a reply.