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

2023/12/2

Change the color of a pixel

Verdreht135 Verdreht135

2023/12/2

#
How do i hange the rgb value of a specific pixel?
danpost danpost

2023/12/4

#
Verdreht135 wrote...
How do i hange the rgb value of a specific pixel?
Create the new color and set it to the specified pixel. The general process is shown below:
GreenfootImage image = getImage(); // get image
Color color = image.getColorAt(0, 0); // get color at some location
int red= color.getRed();; // get red of color
int green = color.getGreen();; // get green of color
int blue = color.getBlue(); // get bue of color
// adjust red/blue/green values here
/**  example -- removing red */
red = 0;
/** **************** */
color = new Color(red, green, blue); // create new color using adjusted rgb values
image.setColorAt(0, 0, color); // set adjusted color to same location
Verdreht135 Verdreht135

2023/12/5

#
danpost wrote...
Verdreht135 wrote...
How do i hange the rgb value of a specific pixel?
Create the new color and set it to the specified pixel. The general process is shown below:
GreenfootImage image = getImage(); // get image
Color color = image.getColorAt(0, 0); // get color at some location
int red= color.getRed();; // get red of color
int green = color.getGreen();; // get green of color
int blue = color.getBlue(); // get bue of color
// adjust red/blue/green values here
/**  example -- removing red */
red = 0;
/** **************** */
color = new Color(red, green, blue); // create new color using adjusted rgb values
image.setColorAt(0, 0, color); // set adjusted color to same location
When i try to put "GreenfootImage image= getImage () into Myworld it says i have to declar a new method.
danpost danpost

2023/12/6

#
Verdreht135 wrote...
When i try to put "GreenfootImage image= getImage () into Myworld it says i have to declar a new method.
In a World subclass, you would use:
GreenfootImage image = getBackground();
You need to login to post a reply.