Image
Fields
Type | Name | Description |
---|---|---|
Pixel[][] | pixels | the 2D array of |
int | width | the width of this |
int | height | the height of this |
static final Color | DEFAULT_BACKGROUND_COLOR = Color.WHITE | the default background color of an empty
|
static final int | MAX_WIDTH = 400 | the maximum width of an
|
static final int | MAX_HEIGHT = 400 | the maximum height of an
|
Method Details
Image
public Image(String filename)
Creates a new Image
object using the pixel information from the specified file.
Parameters
Name | Type | Description |
---|---|---|
filename | String | the filename of the image |
Examples
Image myImage = new Image("sample.jpg");
Image
public Image(int width, int height)
Creates an empty Image
object filled with the default background color.
Parameters
Name | Type | Description |
---|---|---|
width | int | the width of the |
height | int | the height of the |
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
Name | Type | Description |
---|---|---|
source | Image | the source |
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
Name | Type | Description |
---|---|---|
x | int | the x coordinate of the |
y | int | the y coordinate of the |
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
Name | Type | Description |
---|---|---|
x | int | the |
y | int | the |
color | Color | the |
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
Name | Type | Description |
---|---|---|
color | Color | the |
Examples
Image myImage = new Image("sample.jpg");
myImage.clear(Color.VIOLET);