GreenfootImage+class

Class GreenfootImage java.lang.Object greenfoot**.GreenfootImage**
 * greenfoot**

public class GreenfootImage extends java.lang.ObjectAn image to be shown on screen. The image may be loaded from an image file and/or drawn by using various drawing methods.

Version: 2.1 Author: Poul Henriksen 这货老是出现是吧，这是平台的作者，日

Constructor Summary 构造方法 Create a GreenfootImage from another GreenfootImage.
 * GreenfootImage(GreenfootImage image)**

Create an empty (transparent) image with the specified size.
 * GreenfootImage(int width, int height)** 构造一个高height宽width的空图片

Create an image from an image file.
 * GreenfootImage(java.lang.String filename)** 构造一个本地图片组成的显示文件

Method Summary **其他方法**

Clears the image.
 * void clear** 清除图像

Draws the given Image onto this image
 * void drawImage(GreenfootImage image, int x, int y)** 把给定图片画入本图片

void drawLine(int x1, int y1, int x2, int y2) 画一条从(x1,y1)到(x2,y2)的直线 Draw a line, using the current drawing color, between the points (x1, y1) and (x2, y2).

Draw an oval bounded by the specified rectangle with the current drawing color.
 * void drawOval(int x, int y, int width, int height)** 画椭圆

Draws a closed polygon defined by arrays of x and y coordinates.
 * void drawPolygon(int[] xPoints, int[] yPoints, int nPoints)** 画多边形

Draw the outline of the specified rectangle.
 * void drawRect(int x, int y, int width, int height)** 画矩形

Draw a shape directly on the image.
 * void drawShape(java.awt.Shape shape)** 画java.awt.Shape中存在的形状的图形

Draw the text given by the specified string, using the current font and color.
 * void drawString(java.lang.String string, int x, int y)** 在world中显示一些文字

Fill the entire image with the current drawing dcolor.
 * void fill** 填充颜色

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. void fillShape(java.awt.Shape shape) Draw a filled shape directly on the image. java.awt.image.BufferedImage getAwtImage Returns the java.awt.image.BufferedImage that backs this GreenfootImage. java.awt.Color getColor Return the current drawing color. java.awt.Color getColorAt(int x, int y) Return the color at the given pixel. java.awt.Font getFont Get the current font. int getHeight Return the height of the image. Return the current transparency of the image. int getWidth Return the width of the image.
 * int getTransparency 透明度**

Mirrors the image horizontally (flip around the x-axis).
 * void mirrorHorizontally** 镜像效果

Mirrors the image vertically (flip around the y-axis).
 * void mirrorVertically** 竖直镜像效果

Rotates this image around the center.
 * void rotate(int degrees)** 旋转degrees这么大的角度

Scales this image to a new size.
 * void scale(int width, int height)** 放缩

void setColor(java.awt.Color color) Set the current drawing color.

Sets the color at the given pixel to the given color.
 * void setColorAt(int x, int y, java.awt.Color color)** 设置给定像素给定颜色

Set the current font.
 * void setFont(java.awt.Font f)** 设置字体

void setTransparency(int t) Set the transparency of the image. java.lang.String toString Return a text representation of the image. Methods inherited from class java.lang.Object clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

Constructor Detail GreenfootImage public GreenfootImage(java.lang.String filename) throws java.lang.IllegalArgumentExceptionCreate an image from an image file. Supported file formats are JPEG, GIF and PNG. The file name may be an absolute path, or a base name for a file located in the project directory.
 * 下面自己看吧，和前面差不多**

Parameters: filename - Typically the name of a file in the images directory within the project directory. Throws: java.lang.IllegalArgumentException - If the image can not be loaded.

GreenfootImage public GreenfootImage(int width, int height)Create an empty (transparent) image with the specified size.

Parameters: width - The width of the image in pixels. height - The height of the image in pixels.

GreenfootImage public GreenfootImage(GreenfootImage image) throws java.lang.IllegalArgumentExceptionCreate a GreenfootImage from another GreenfootImage.

Throws: java.lang.IllegalArgumentException Method Detail getAwtImage public java.awt.image.BufferedImage getAwtImageReturns the java.awt.image.BufferedImage that backs this GreenfootImage. Any changes to the returned image will be reflected in the GreenfootImage.

Returns: The java.awt.image.BufferedImage backing this GreenfootImage Since: Greenfoot version 1.0.2

getWidth public int getWidthReturn the width of the image.

Returns: Width of the image.

getHeight public int getHeightReturn the height of the image.

Returns: Height of the image.

rotate public void rotate(int degrees)Rotates this image around the center.

Parameters: degrees -

scale public void scale(int width, int height)Scales this image to a new size.

Parameters: width - Width of new image height - Height of new image

mirrorVertically public void mirrorVerticallyMirrors the image vertically (flip around the y-axis).

mirrorHorizontally public void mirrorHorizontallyMirrors the image horizontally (flip around the x-axis).

fill public void fillFill the entire image with the current drawing dcolor.

drawImage public void drawImage(GreenfootImage image, int x, int y)Draws the given Image onto this image

Parameters: image - The image to draw onto this one. x - x-coordinate for drawing the image. y - y-coordinate for drawing the image.

setFont public void setFont(java.awt.Font f)Set the current font. This font will be used for subsequent text operations.

getFont public java.awt.Font getFontGet the current font.

setColor public void setColor(java.awt.Color color)Set the current drawing color. This color will be used for subsequent drawing operations.

Parameters: color - The color to be used.

getColor public java.awt.Color getColorReturn the current drawing color.

Returns: The current color.

getColorAt public java.awt.Color getColorAt(int x, int y)Return the color at the given pixel.

Throws: java.lang.IndexOutOfBoundsException - If the pixel location is not within the image bounds.

setColorAt public void setColorAt(int x, int y, java.awt.Color color)Sets the color at the given pixel to the given color.

setTransparency public void setTransparency(int t)Set the transparency of the image.

Parameters: t - A value in the range 0 to 255. 0 is completely transparent (invisible) and 255 is completely opaque (the default).

getTransparency public int getTransparencyReturn the current transparency of the image.

Returns: A value in the range 0 to 255. 0 is completely transparent (invisible) and 255 is completely opaque (the default).

fillRect public void fillRect(int x, int y, int width, int height)Fill the specified rectangle. The left and right edges of the rectangle are at 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.

Parameters: 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.

clear public void clearClears the image.

drawRect public void drawRect(int x, int y, int width, int height)Draw the outline of the specified rectangle. The left and right edges of the rectangle are at x and x + width. The top and bottom edges are at y and y + height. The rectangle is drawn using the current color.

Parameters: 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.

drawString public void drawString(java.lang.String string, int x, int y)Draw the text given by the specified string, using the current font and color. The baseline of the leftmost character is at position ( x, y ).

Parameters: string - the string to be drawn. x - the x coordinate. y - the y coordinate.

drawShape public void drawShape(java.awt.Shape shape)Draw a shape directly on the image. Shapes are specified by the shape interface.

Parameters: shape - the shape to be drawn.

fillShape public void fillShape(java.awt.Shape shape)Draw a filled shape directly on the image. Shapes are specified by the shape interface.

Parameters: shape - the shape to be drawn.

fillOval public void fillOval(int x, int y, int width, int height)Fill an oval bounded by the specified rectangle with the current drawing color.

Parameters: 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.

drawOval public void drawOval(int x, int y, int width, int height)Draw an oval bounded by the specified rectangle with the current drawing color.

Parameters: 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.

fillPolygon public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints)Fill a closed polygon defined by arrays of x and y coordinates. 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.

Parameters: xPoints - a an array of x coordinates. yPoints - a an array of y coordinates. nPoints - a the total number of points.

drawPolygon public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints)Draws a closed polygon defined by arrays of x and y coordinates. Each pair of (x, y) coordinates defines a point. 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.

Parameters: xPoints - an array of x coordinates. yPoints - an array of y coordinates. nPoints - the total number of points.

drawLine public 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).

Parameters: 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.

toString public java.lang.String toStringReturn a text representation of the image.

Overrides: toString in class java.lang.Object