Lab 2: Image Transformer
Overview
In this assignment, you will provide a simple Graphical User Interface that allows image files to be transformed using several specified transformations.
Pre-Lab (DUE BEFORE LAB - see due date in Canvas)
As part of the pre-lab activity you must ensure that you have JavaFX installed on your laptop.
Assignment
Create a JavaFX program that provides a user interface that matches the screenshot below.
When the user enters an input image filename in the first text field, an output image filename in the second text field, and then presses the Copy button, the program will read the specified image file and write it to the specified output file.
Details
Create a ImageCopy
class that extends the Application
class. This class will
include your start()
method that will create the GUI.
Replacing mocked
Package
Copy your ImageIO
class implementation from your lab 1 project into
this project and incorporate feedback from your instructor (if available).
Instead of using the classes/interfaces provided by the mocked
package,
you will use several JavaFX classes/interfaces:
Image
— Represents graphical images.WritableImage
— Represents a custom graphical image that is constructed from pixels supplied by the application.PixelReader
— Defines methods for retrieving pixel data from anImage
.PixelWriter
— Defines methods for writing the pixel data of aWritableImage
.
To use these, replace the imports in ImageIO
that used mocked
with javafx.scene.image
.
Support for .png
Image Files
You must provide support for reading and writing images in the .png
format. You must
create two private class methods:
readPNG(Path path)
— Reads in the specified image file in.png
format and returns anImage
object containing the image.writePNG(Path path, Image image)
— Writes the specified image to the specified path using the.png
file format.
An Image
class constructor supports reading PNG images. Writing PNG images
is a bit more involved. It can be done using the javax.imageio.ImageIO.write()
method, and you can use the javafx.embed.swing.SwingFXUtils.fromFXImage()
method to get a BufferedImage
(that is a RenderedImage
).
Update the public read()
and write()
methods to call the readPNG()
and writePNG()
methods when appropriate.
Exception Handling
If any problems are encountered with reading the input files or writing the output file, the program should display a useful error message to the console and continue running. The program should not crash or display any exceptions.
Just For Fun
Ambitious students may wish to:
- Display all of the input and/or output image.
You can display an Image
in the Scene
by placing the Image
in a ImageView
.
Acknowledgement
This laboratory assignment, developed by Dr. Chris Taylor.