21.2. Loading, Displaying and Scaling Images

Java’s multimedia capabilities include graphics, images, animations, sounds and video. We begin our discussion with images. We will use several different images in this chapter. Developers can create such images with any image software, such as Adobe® Photoshop™, Jasc® Paint Shop Pro™ or Microsoft® Paint.

The applet of Fig. 21.1 demonstrates loading an Image (package java.awt) and loading an ImageIcon (package javax.swing). Both classes are used to load and display images. The applet displays the Image in its original size and scaled to a larger size, using two versions of Graphics method drawImage. The applet also draws the ImageIcon, using the icon’s method paintIcon. Class ImageIcon implements ...

Get Java™ How to Program, Seventh Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.