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
GrayFilterclass that you can use to do your own filtering. (Normally you don’t call this, but usecreateDisabledImage()instead.) Both thebrighterandpercentarguments 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 theGrayFilterclass withbrighterturned on and a graypercentof 50.- public int filterRGB(int x, int y, int rgb)
Overrides the
filterRGB()method inRGBImageFilter, converts thergbpixel 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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access