public class RasterImage extends java.lang.Object implements java.lang.Iterable<Pixel>
show
method. The window will have the default window decorators and the
string that appears as the title is an attribute of the RasterImage object.
This class provides constructors for the instantiation of a raster graphic
image (i) from a file name, (ii) from another image, or (iii) from a width
and height specification. This class provides accessor methods for the pixels
of the raster image.Constructor and Description |
---|
RasterImage()
Constructs a raster image consisting of only white pixels, with a default
width of 200 and a default height of 100.
|
RasterImage(int width,
int height)
Constructs a raster image consisting of only white pixels, with a width
and height as specified by the passed parameter values.
|
RasterImage(RasterImage copyPicture)
Constructs a new instance of this class that has the same state as the
passed instance.
|
RasterImage(java.lang.String fileName)
Constructs a raster image consisting of the pixels derived from the image
that is specified in the file that is passed as parameter.
|
Modifier and Type | Method and Description |
---|---|
void |
addMessage(java.lang.String message,
int xPos,
int yPos)
Causes the passed string to be added to this raster image, where the
bottom left-hand anchor point of the string will be positioned at the
specified coordinates.
|
void |
blacken(int rowIndex)
Mutate the colour of all of the pixels in the specified row to be black.
|
void |
copyPicture(RasterImage otherRasterImage)
Mutates this raster image to have the same state as the passed raster
image.
|
RasterImage |
createResizedCopy(int height)
Returns a new raster image object that is based on this raster image,
except that the new raster image will be scaled to have the passed
height.
|
void |
explore()
Causes this picture to be shown in a new PictureExplorer window.
|
java.lang.String |
getFileName()
Returns the name of the file that is associated with this raster image
picture, if any exists.
|
java.awt.Graphics2D |
getGraphics2D()
Returns the Graphics2D instance that is associated with this ratser
image.
|
int |
getHeight()
Returns the height of this picture in pixels.
|
java.awt.Image |
getImage()
Returns the Image from the picture
|
Pixel |
getPixel(int x,
int y)
Returns the Pixel object at the specified (x,y) coordinate.
|
Pixel[] |
getPixelArray()
Returns an array of Pixels for this picture, which is composed of the
pixels from the first row of this raster (from left to right), followed
by the next row, and so on until the final row.
|
int |
getPixelColor(int x,
int y)
Returns the colour of the pixel at the specified coordinate, in the
integer color representation.
|
java.lang.String |
getTitle()
Returns the string that is used in the title bar of the window that is
used for the display of this raster image.
|
int |
getWidth()
Returns the width of this picture in pixels.
|
java.util.Iterator<Pixel> |
iterator() |
void |
modifyRowColour(int rowIndex,
java.awt.Color theNewColor)
Cause the pixels in the specified row to change to the specified colour.
|
void |
repaint()
This method causes the window which contains this raster image to be
marked that it needs to be redrawn.
|
void |
setAllPixelsToAColor(java.awt.Color color)
Mutate all of this image's pixels to have the passed color
|
void |
setBasicPixel(int x,
int y,
int rgb)
Sets the colour of the specified pixel, as encoded in the passed int
value.
|
void |
setTitle(java.lang.String titleString)
Set the string the string that is used in the title bar of the window
that is used for the display of this raster image.
|
void |
show()
Causes this raster image to be displayed graphically on the screen
display device of the runtime platform of the client application.
|
java.lang.String |
toString()
Returns a descriptive string about this raster image which includes this
raster image's height and width and associated filename, if any.
|
void |
write(java.lang.String fileName)
Causes the contents of this raster image to be written to a file that has
the passed filename and in a image format that is specified by the
extension of the passed filename (such as .bmp or .jpg).
|
public RasterImage()
public RasterImage(int width, int height)
width
- the width of the raster image, expressed in number of pixelsheight
- the height of the raster image, expressed in number of pixelspublic RasterImage(java.lang.String fileName)
fileName
- the name of the file that contains the source imagejava.lang.Exception
- as described abovepublic RasterImage(RasterImage copyPicture)
copyPicture
- the picture to copy frompublic void copyPicture(RasterImage otherRasterImage)
otherRasterImage
- the raster image from which the attributes are to be copied.public void setAllPixelsToAColor(java.awt.Color color)
color
- the new color for all of the pixelspublic void blacken(int rowIndex)
rowIndex
- as described abovepublic void modifyRowColour(int rowIndex, java.awt.Color theNewColor)
rowIndex
- as described abovetheNewColor
- the new colour of the pixels in the rowpublic java.awt.Graphics2D getGraphics2D()
public java.lang.String getFileName()
public java.lang.String getTitle()
public void setTitle(java.lang.String titleString)
titleString
- as described abovepublic int getWidth()
public int getHeight()
public java.awt.Image getImage()
public int getPixelColor(int x, int y)
x
- the x position of the pixely
- the y position of the pixelpublic void setBasicPixel(int x, int y, int rgb)
x
- the x position of the pixely
- the y position of the pixelrgb
- the new rgb value of the pixel (alpha, red, green, blue)public Pixel getPixel(int x, int y)
x
- the x position of the pixely
- the y position of the pixelpublic Pixel[] getPixelArray()
public void show()
public void explore()
public void repaint()
public void addMessage(java.lang.String message, int xPos, int yPos)
message
- the message to draw on the buffered imagexPos
- the leftmost point of the string in xyPos
- the bottom of the string in ypublic RasterImage createResizedCopy(int height)
height
- the target height of the new raster image, a value that is
strictly larger than 0public void write(java.lang.String fileName)
fileName
- the name of the file to which this raster image should be
written.public java.lang.String toString()
toString
in class java.lang.Object