Slot18 2D Graphics Images
Slot18 2D Graphics Images
Reference: Java-Tutorials/tutorial-2015/2d/images/index.html
Contents
Introduction
The java.awt.Image Class
The java.awt.image.BufferedImage Class
The java.awt
Reading/Loading an Image
Drawing an Image
Demonstrations
Teach yourself
Creating and drawing to an image
Writing/Saving an image
2
1- Introduction
3
Introduction…
The are two main classes that you must learn about to work with
images:
The java.awt.Image class is the superclass that represents graphical images
as rectangular arrays of pixels.
The java.awt.image.BufferedImage class, which extends the Image class to
allow the application to operate directly with image data (for example,
retrieving or setting up the pixel color). Applications can directly construct
instances of this class.
The BufferedImage class is a cornerstone of the Java 2D immediate-
mode imaging API. It manages the image in memory and provides
methods for storing, interpreting, and obtaining pixel data.
Since BufferedImage is a subclass of Image it can be rendered by
the Graphics and Graphics2D methods that accept
an Image parameter.
A BufferedImage is essentially an Image with an accessible data buffer.
It is therefore more efficient to work directly with BufferedImage.
A BufferedImage has a ColorModel and a Raster of image data. The
4 ColorModel provides a color interpretation of the image's pixel data.
Introduction…
5
2- The java.awt.Image Class
6
3- The java.awt.image.BufferedImage
7
4- Reading/Loading an Image
9
Demonstration
JSplitPane1 Properties
Orientation:
HORIZONTAL_SPLIT
DividerLocation: 250
lstFiles Properties
SelectionMode: SINGLE
Model: Blank
pView Properties
PreferredSize: (1000,800)
12
Code
The program
supports auto-
sliding through a
thread. So, an
inner class is
declared.
13
Code
Step 2
Step 3
Step
1:
Right
click
to the
listbox
We want the list of filenames (the variable list)
will be the model of the listbox lstList. Return to
the design window to complete this work.
14 Step 4
Code
15
Code
16
Code
17
Code
18
Code
19
Code
20
Summary
Introduction
The java.awt.Image Class
The java.awt.image.BufferedImage Class
The java.awt
Reading/Loading an Image
Drawing an Image
Demonstrations
21
Summary
Introduction
Reading/Loading an Image
Drawing an Image
Creating and Drawing to an Image
Demonstration
22
Thank You
23