Java Lab Documentation

Image

Category:org.code.media

Fields

TypeNameDescription
Pixel[][]pixels

the 2D array of Pixel objects that make up this Image

intwidth

the width of this Image

intheight

the height of this Image

static final ColorDEFAULT_BACKGROUND_COLOR = Color.WHITE

the default background color of an empty Image

Image.DEFAULT_BACKGROUND_COLOR
static final intMAX_WIDTH = 400

the maximum width of an Image

Image.MAX_WIDTH
static final intMAX_HEIGHT = 400

the maximum height of an Image

Image.MAX_HEIGHT

Method Details

Image

public Image(String filename)

Creates a new Image object using the pixel information from the specified file.

Parameters

NameTypeRequired?Description
filenameString

the filename of the image

Examples

Image myImage = new Image("sample.jpg");
Overloads

Image

public Image(int width, int height)

Creates an empty Image object filled with the default background color.

Parameters

NameTypeRequired?Description
widthint

the width of the Image to create

heightint

the height of the Image to create

Examples

Image myImage = new Image(200, 200);

Image

public Image(Image source)

Creates a new Image object by copying the pixels from the specified Image object.

Parameters

NameTypeRequired?Description
sourceImage

the source Image object to copy

Examples

Image myImage = new Image("sample.jpg");
Image imageCopy = new Image(myImage);

getPixel

public Pixel getPixel(int x, int y)

Gets the Pixel object at the specified x and y coordinate.

Parameters

NameTypeRequired?Description
xint

the x coordinate of the Pixel

yint

the y coordinate of the Pixel

Examples

Image myImage = new Image("sample.jpg");
Pixel singlePixel = myImage.getPixel(10, 20);
// singlePixel points to the Pixel object located at (10, 20) in myImage

setPixel

public void setPixel(int x, int y, Color color)

Sets the Pixel at the specified x and y coordinate to the Color provided.

Parameters

NameTypeRequired?Description
xint

the x coordinate to set the Pixel

yint

the y coordinate to set the Pixel

colorColor

the Color to use to set the Pixel

Examples

Image myImage = new Image("sample.jpg");
Color myColor = new Color(166, 99, 204);
myImage.setPixel(10, 20, myColor);

getWidth

public int getWidth()

Returns the width of this Image in pixels.

Examples

Image myImage = new Image("sample.jpg");
int myImageWidth = myImage.getWidth();

getHeight

public int getHeight()

Returns the height of this Image in pixels.

Examples

Image myImage = new Image("sample.jpg");
int myImageHeight = myImage.getHeight();

clear

public void clear(Color color)

Clears this Image and fills it with the specified Color.

Parameters

NameTypeRequired?Description
colorColor

the Color to fill this Image

Examples

Image myImage = new Image("sample.jpg");
myImage.clear(Color.VIOLET);