- Forward


Image Input and Output
in Java


Prof. David Bernstein
James Madison University

Computer Science Department
bernstdh@jmu.edu

Print

Overview
Back SMYC Forward
  • Creating Images
  • Reading Images
  • Writing Images
  • An Image Writing System
Creating Images
Back SMYC Forward
  • The BufferedImage Class:
    • An Image with accessible, in-memory image data
  • Constructing an Instance:
    • BufferedImage(int width, int height, int imageType)
  • Rendering:
    • Get a Graphics or Graphics2D object using the getGraphics() or createGraphics() methods
Reading Images
Back SMYC Forward
  • The ImageIO Class:
    • A utility class
  • The Easiest Approach:
    • static BufferedImage read(File input)
Writing Images
Back SMYC Forward
  • The ImageIO Class:
    • A utility class
  • The Easiest Approach:
    • static boolean write(BufferedImage image, String format, File output)
An Example
Back SMYC Forward
  • An Analogy:
    • The PrinterJob class can be used to control the printing of Printable objects
  • Wouldn't It Be Useful?
    • To have a class that can control the taking and saving of "snapshot" images of anything with a paint() method
An Example (cont.)
Back SMYC Forward
javaexamples/printing/PaintJob.java
 
There's Always More to Learn
Back -