public class GreenfootImage
extends java.lang.Object
| Constructor and Description |
|---|
GreenfootImage(GreenfootImage image)
Create a GreenfootImage from another GreenfootImage.
|
GreenfootImage(int width,
int height)
Create an empty (transparent) image with the specified size.
|
GreenfootImage(java.lang.String filename)
Create an image from an image file.
|
GreenfootImage(java.lang.String string,
int size,
greenfoot.awt.Color foreground,
greenfoot.awt.Color background)
Creates an image with the given string drawn as text using the given font
size, with the given foreground color on the given background color.
|
GreenfootImage(java.lang.String string,
int size,
int foreground,
int background)
Creates an image with the given string drawn as text using the given font
size, with the given foreground color on the given background color.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Clears the image.
|
void |
drawImage(GreenfootImage image,
int x,
int y)
Draws the given Image onto this image
|
void |
drawLine(int x1,
int y1,
int x2,
int y2)
Draw a line, using the current drawing color, between the points
(x1, y1) and (x2, y2). |
void |
drawOval(int x,
int y,
int width,
int height)
Draw an oval bounded by the specified rectangle with the current drawing
color.
|
void |
drawPolygon(int[] xPoints,
int[] yPoints,
int nPoints)
Draws a closed polygon defined by arrays of x and y
coordinates.
|
void |
drawRect(int x,
int y,
int width,
int height)
Draw the outline of the specified rectangle.
|
void |
drawString(java.lang.String string,
int x,
int y)
Draw the text given by the specified string, using the current font and
color.
|
void |
fill()
Fill the entire image with the current drawing dcolor.
|
void |
fillOval(int x,
int y,
int width,
int height)
Fill an oval bounded by the specified rectangle with the current drawing
color.
|
void |
fillPolygon(int[] xPoints,
int[] yPoints,
int nPoints)
Fill a closed polygon defined by arrays of x and y
coordinates.
|
void |
fillRect(int x,
int y,
int width,
int height)
Fill the specified rectangle.
|
Bitmap |
getAwtImage()
Returns the java.awt.image.BufferedImage that backs this GreenfootImage.
|
greenfoot.awt.Color |
getColor()
Return the current drawing color.
|
greenfoot.awt.Color |
getColorAt(int x,
int y)
Return the color at the given pixel.
|
greenfoot.awt.Font |
getFont()
Get the current font.
|
int |
getHeight()
Return the height of the image.
|
int |
getTransparency()
Return the current transparency of the image.
|
int |
getWidth()
Return the width of the image.
|
void |
mirrorHorizontally()
Mirrors the image horizontally (the left of the image becomes the right,
and vice versa).
|
void |
mirrorVertically()
Mirrors the image vertically (the top of the image becomes the bottom,
and vice versa).
|
void |
rotate(int degrees)
Rotates this image around the center.
|
void |
scale(int width,
int height)
Scales this image to a new size.
|
void |
setColor(greenfoot.awt.Color color)
Set the current drawing color.
|
void |
setColor(int color)
Set the current drawing color.
|
void |
setColorAt(int x,
int y,
greenfoot.awt.Color color)
Sets the color at the given pixel to the given color.
|
void |
setColorAt(int x,
int y,
int color)
Sets the color at the given pixel to the given color.
|
void |
setFont(greenfoot.awt.Font f)
Set the current font.
|
void |
setTransparency(int t)
Set the transparency of the image.
|
java.lang.String |
toString()
Return a text representation of the image.
|
public GreenfootImage(GreenfootImage image) throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentExceptionpublic GreenfootImage(int width,
int height)
width - The width of the image in pixels.height - The height of the image in pixels.public GreenfootImage(java.lang.String filename)
throws java.lang.IllegalArgumentException
The file name may be an absolute path, or a base name for a file located in the project directory.
filename - Typically the name of a file in the images directory within
the project directory.java.lang.IllegalArgumentException - If the image can not be loaded.public GreenfootImage(java.lang.String string,
int size,
int foreground,
int background)
string - the string to be drawnsize - the requested height in pixels of each line of text (the
actual height may be different by a pixel or so)foreground - the color of the text. Since Greenfoot 2.2.0, passing null
will use black.background - the color of the image behind the text. Since Greenfoot 2.2.0,
passing null with leave the background transparent.public GreenfootImage(java.lang.String string,
int size,
greenfoot.awt.Color foreground,
greenfoot.awt.Color background)
string - the string to be drawnsize - the requested height in pixels of each line of text (the
actual height may be different by a pixel or so)foreground - the color of the text. Since Greenfoot 2.2.0, passing null
will use black.background - the color of the image behind the text. Since Greenfoot 2.2.0,
passing null with leave the background transparent.public void clear()
public void drawImage(GreenfootImage image, int x, int y)
image - The image to draw onto this one.x - x-coordinate for drawing the image.y - y-coordinate for drawing the image.public void drawLine(int x1,
int y1,
int x2,
int y2)
(x1, y1) and (x2, y2).x1 - the first point's x coordinate.y1 - the first point's y coordinate.x2 - the second point's x coordinate.y2 - the second point's y coordinate.public void drawOval(int x,
int y,
int width,
int height)
x - the x coordinate of the upper left corner of the oval
to be filled.y - the y coordinate of the upper left corner of the oval
to be filled.width - the width of the oval to be filled.height - the height of the oval to be filled.public void drawPolygon(int[] xPoints,
int[] yPoints,
int nPoints)
This method draws the polygon defined by nPoint line
segments, where the first nPoint - 1 line segments
are line segments from
(xPoints[i - 1], yPoints[i - 1]) to
(xPoints[i], yPoints[i]), for
1 ≤ i ≤ nPoints. The figure
is automatically closed by drawing a line connecting the final point to
the first point, if those points are different.
xPoints - an array of x coordinates.yPoints - an array of y coordinates.nPoints - the total number of points.public void drawRect(int x,
int y,
int width,
int height)
x and x + width.
The top and bottom edges are at y and
y + height. The rectangle is drawn using the
current color.x - the x coordinate of the rectangle to be drawn.y - the y coordinate of the rectangle to be drawn.width - the width of the rectangle to be drawn.height - the height of the rectangle to be drawn.public void drawString(java.lang.String string,
int x,
int y)
string - the string to be drawn.x - the x coordinate.y - the y coordinate.public void fill()
public void fillOval(int x,
int y,
int width,
int height)
x - the x coordinate of the upper left corner of the oval
to be filled.y - the y coordinate of the upper left corner of the oval
to be filled.width - the width of the oval to be filled.height - the height of the oval to be filled.public void fillPolygon(int[] xPoints,
int[] yPoints,
int nPoints)
This method draws the polygon defined by nPoint line
segments, where the first nPoint - 1 line segments
are line segments from
(xPoints[i - 1], yPoints[i - 1]) to
(xPoints[i], yPoints[i]), for 1 ≤ i
≤ nPoints. The figure is automatically
closed by drawing a line connecting the final point to the first point,
if those points are different.
The area inside the polygon is defined using an even-odd fill rule, also known as the alternating rule.
xPoints - a an array of x coordinates.yPoints - a an array of y coordinates.nPoints - a the total number of points.public void fillRect(int x,
int y,
int width,
int height)
x and x + width - 1.
The top and bottom edges are at y and
y + height - 1. The resulting rectangle
covers an area width pixels wide by height
pixels tall. The rectangle is filled using the current color.x - the x coordinate of the rectangle to be filled.y - the y coordinate of the rectangle to be filled.width - the width of the rectangle to be filled.height - the height of the rectangle to be filled.public Bitmap getAwtImage()
public greenfoot.awt.Color getColor()
public greenfoot.awt.Color getColorAt(int x,
int y)
java.lang.IndexOutOfBoundsException - If the pixel location is not within the image bounds.public greenfoot.awt.Font getFont()
public int getHeight()
public int getTransparency()
public int getWidth()
public void mirrorHorizontally()
public void mirrorVertically()
public void rotate(int degrees)
degrees - public void scale(int width,
int height)
width - Width of new imageheight - Height of new imagepublic void setColor(greenfoot.awt.Color color)
color - The color to be used.public void setColor(int color)
color - The color to be used.public void setColorAt(int x,
int y,
greenfoot.awt.Color color)
public void setColorAt(int x,
int y,
int color)
public void setFont(greenfoot.awt.Font f)
public void setTransparency(int t)
t - A value in the range 0 to 255. 0 is completely transparent
(invisible) and 255 is completely opaque (the default).public java.lang.String toString()
toString in class java.lang.Object