Image Utilities
The last category of utility classes to look at is image utilities. The Swing package contains a class that can come in handy for generating images.
The GrayFilter Class
The GrayFilter
class is an extension of the
java.awt.image.RGBImageFilter
class. This class
contains a static method that returns a “disabled”
version of an image passed in. The image is converted to a grayscale
version, and some lighter parts of the image are amplified to ensure
the image is recognizable. All of the components that can display
images use this class to present a default disabled version of the
image if an explicit disabled image was not provided.
Constructors
- public GrayFilter(boolean brighter, int percent)
Creates an instance of the
GrayFilter
class that you can use to do your own filtering. (Normally you don’t call this, but usecreateDisabledImage()
instead.) Both thebrighter
andpercent
arguments are used to convert color pixels to appropriately shaded gray pixels.
Image Methods
- public static Image createDisabledImage(Image i)
Use this method to retrieve a grayed-out version of the image
i
. This method creates an instance of theGrayFilter
class withbrighter
turned on and a graypercent
of 50.- public int filterRGB(int x, int y, int rgb)
Overrides the
filterRGB()
method inRGBImageFilter
, converts thergb
pixel to a gray pixel, and returns that.
The Renderer Interface
The Swing package includes a
Renderer
interface with the following
methods:
- public Component getComponent()
Returns ...
Get Java Swing 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.