|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectimg.DigitalPicture
public class DigitalPicture
This class encapsulates a digital picture, which can be created from a file name, from another image, or from a width and height specification. A digital picture has accessor and mutator methods for its pixels. A digital picture has an associated string which serves as the picture's title. A digital picture can be displayed graphically. As well, some basic interaction with a digital picture is provided via the PictureExplorer. This class is based on the Picture class from Guzdial and Ericson, with explanatory comments and modifications provided by various contributors: sdc@cs.albany.edu, ericson@cc.gatech.edu. mb@cse.yorku.ca
Constructor Summary | |
---|---|
DigitalPicture()
Default constructor, which instantiates a blank picture consisting of only white pixels, with a default width of 200 and a default height of 100. |
|
DigitalPicture(DigitalPicture copyPicture)
Constructs a new instance of this class that has the same state as the passed instance. |
|
DigitalPicture(int width,
int height)
Constructs a picture with the width and height as specified by the passed parameter values. |
|
DigitalPicture(java.lang.String fileName)
Constructs a picture from the image in the filename that is passed as parameter. |
Method Summary | |
---|---|
void |
addMessage(java.lang.String message,
int xPos,
int yPos)
Draw the passed string on this picture at the specified coordinates. |
void |
blacken(int row)
The method causes all of the pixels in the specified row to be changed to a black colour. |
void |
copyPicture(DigitalPicture sourcePicture)
Causes all attributes of this object to be copied from the passed source picture. |
java.awt.Graphics2D |
createGraphics()
Returns the Graphics2D instance (encapsulates the graphics context for the platform upon which the virtual machine is running), which can then be used to do 2D drawing on the picture |
void |
explore()
Causes this picture to be shown in a new PictureExplorer window. |
int |
getBasicPixel(int x,
int y)
Returns the colour information about the specified pixel, as encoded in an int value. |
java.awt.image.BufferedImage |
getBufferedImage()
Returns the buffered image associated with this picture. |
java.lang.String |
getExtension()
Returns the extension of the filename used to create this picture (e.g., jpg or bmp), if one exists (otherwise, null is returned). |
java.lang.String |
getFileName()
Get the name of the file associated with this digital picture, if one exists. |
java.awt.Graphics |
getGraphics()
Returns the Graphics instance (encapsulates the graphics context for the platform upon which the virtual machine is running). |
java.awt.Graphics2D |
getGraphics2D()
Returns the Graphics2D instance (encapsulates the graphics context for the platform upon which the virtual machine is running). |
int |
getHeight()
Returns the height of this picture in pixels. |
java.awt.Image |
getImage()
Returns the Image from the picture |
PictureFrame |
getPictureFrame()
Returns the PictureFrame object that associated with this picture (it may be null) |
DigitalPicture |
getPictureWithHeight(int height)
Method to create a new picture of the passed height. |
Pixel |
getPixel(int x,
int y)
Returns the Pixel object at the specified (x,y) coordinate. |
Pixel[] |
getPixels()
Returns a one-dimensional array of Pixels for this picture |
java.lang.String |
getTitle()
Get the string that encapsulates the title that is associated with this digital picture. |
java.awt.geom.Rectangle2D |
getTranslationEnclosingRectangle(java.awt.geom.AffineTransform trans)
Method to get the coordinates of the enclosing rectangle after this transformation is applied to the current picture |
int |
getWidth()
Returns the width of this picture in pixels. |
void |
load(java.awt.Image image)
Load the buffered image with the passed image |
void |
load(java.lang.String fileName)
Loads the picture from the passed file name, if a picture exists in the file. |
void |
modifyRowColour(int row,
java.awt.Color theNewColor)
Cause the pixels in the specified row to change to the specifed colour. |
void |
repaint()
Forces this picture to redraw itself. |
void |
setAllPixelsToAColor(java.awt.Color color)
Set the color of all of the pixels to 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 |
setPictureFrame(PictureFrame pictureFrame)
Set the passed PictureFrame object to be associated with this picture. |
void |
setTitle(java.lang.String title)
Set the string that encapsulates the title that is associated with this digital picture. |
void |
show()
Causes this picture to be displayed graphically (using the PictureFrame object that is associated with this picture). |
java.lang.String |
toString()
Return a string representation of this Picture. |
void |
write(java.lang.String fileName)
Method to write the contents of the picture to a file with the passed name |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public DigitalPicture()
public DigitalPicture(int width, int height)
width
- the width of the desired pictureheight
- the height of the desired picturepublic DigitalPicture(java.lang.String fileName)
fileName
- the name of the file that contains the source image
java.lang.Exception
- as described abovepublic DigitalPicture(DigitalPicture copyPicture)
copyPicture
- the picture to copy fromMethod Detail |
---|
public java.lang.String getExtension()
public void copyPicture(DigitalPicture sourcePicture)
sourcePicture
- the picture object from which the attributes should be copied.public void setAllPixelsToAColor(java.awt.Color color)
color
- the new color for all of the pixelspublic void blacken(int row)
row
- public void modifyRowColour(int row, java.awt.Color theNewColor)
row
- the index of the row to be changedtheNewColor
- the new colour of the rowpublic java.awt.image.BufferedImage getBufferedImage()
getBufferedImage
in interface AbstractDigitalPicture
public java.awt.Graphics getGraphics()
public java.awt.Graphics2D getGraphics2D()
public java.awt.Graphics2D createGraphics()
public java.lang.String getFileName()
getFileName
in interface AbstractDigitalPicture
public java.lang.String getTitle()
getTitle
in interface AbstractDigitalPicture
public void setTitle(java.lang.String title)
setTitle
in interface AbstractDigitalPicture
public int getWidth()
getWidth
in interface AbstractDigitalPicture
public int getHeight()
getHeight
in interface AbstractDigitalPicture
public PictureFrame getPictureFrame()
public void setPictureFrame(PictureFrame pictureFrame)
pictureFrame
- the picture frame to usepublic java.awt.Image getImage()
getImage
in interface AbstractDigitalPicture
public int getBasicPixel(int x, int y)
getBasicPixel
in interface AbstractDigitalPicture
x
- the x position of the pixely
- the y position of the pixel
public void setBasicPixel(int x, int y, int rgb)
setBasicPixel
in interface AbstractDigitalPicture
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)
getPixel
in interface AbstractDigitalPicture
x
- the x position of the pixely
- the y position of the pixel
public Pixel[] getPixels()
public void load(java.awt.Image image)
load
in interface AbstractDigitalPicture
image
- the image to usepublic void show()
show
in interface AbstractDigitalPicture
public void explore()
public void repaint()
public void load(java.lang.String fileName) throws java.lang.Exception
load
in interface AbstractDigitalPicture
fileName
- the file name to use to load the picture from
java.lang.Exception
- as described abovepublic 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 DigitalPicture getPictureWithHeight(int height)
height
- the desired height
public void write(java.lang.String fileName)
fileName
- the name of the file to write the picture topublic java.awt.geom.Rectangle2D getTranslationEnclosingRectangle(java.awt.geom.AffineTransform trans)
public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |