This lab includes two packages within the src folder: code and image. If you open the code package, you will see a single class called ImageManipulation. This is the only class that you will be writing code in. If you open the image package, you will see four classes within it: APImage, ImageFileFilter, ImagePanel, and Pixel. The only two classes that you will directly use within your program are APImage and Pixel. The APImage class represents an image as a two-dimensional grid of Pixel objects. You will use the constructors and methods in the APImage class and Pixel class in order to complete this lab. The methods for the APImage and Pixel class are listed below.
APImage CONSTRUCTORS | WHAT IT DOES |
---|---|
APImage() | Creates an image from a file dialog selection, or creates a blank, 200 by 200, black image if the user cancels the dialog. |
APImage (String filename) | Creates an image from the given file; throws an exception if the file does not exist or the file is not in JPEG format. |
APImage (int width, int height) | Creates a blank image of the given width and height, with a color of black. |
APImage METHODS | WHAT IT DOES |
---|---|
int getWidth() | Returns the images width in pixels |
int getHeight() | Returns the images height in pixels |
Pixel getPixel(int x, int y) | Returns the pixel at the given position, where x is the column and y is the row |
void setPixel(int x, int y, Pixel p) | Resets the pixel at the given position, where x is the column and y is the row |
void draw() | Makes the image’s window visible and draws the image in it |
APImage clone() | Returns a new instance of APImage that is a copy of this image |
String toString() | Returns the string representation of the image containing the information (filename, width, and height) |
Pixel CONSTRUCTOR | WHAT IT DOES |
---|---|
Pixel(int red, int green, int blue) | Creates a pixel with the given RGB values |
Pixel METHOD | WHAT IT DOES |
---|---|
int getRed() | Returns the pixel’s red value |
int getGreen() | Returns the pixel’s green value |
int getBlue() | Returns the pixel’s blue value |
void setRed(int red) | Resets the pixel’s red value to red |
void setGreen(int green) | Resets the pixel’s green value to green |
void setBlue(int blue) | Resets the pixel’s blue value to blue |
Pixel clone() | Returns a copy of this pixel |
String toString() | Returns the string representation of the pixel (red, green, and blue values) |
There are six challenges in this lab (challenge 0, challenge 1, challenge 2, challenge 3, challenge 4, and challenge 5). To complete this lab, you will need to complete challenges 0, 1, 2, and 3. Challenges 4 and 5 are optional and you should only attempt them if you are, like, really confident and are really feeling yourself #slay. Each challenge involves manipulating an image. The image that you will be manipulating is located in your project and is called cyberpunk2077.jpg.
Below are examples of what your output should look like after calling each method.
Challenge 0:
Challenge 1:
Challenge 2:
Challenge 3 (threshold 20):
Challenge 4:
Challenge 5:
As always, good luck, have fun! =)