Class GraphicsUtilities

java.lang.Object
org.jxmapviewer.util.GraphicsUtilities

public class GraphicsUtilities
extends java.lang.Object

GraphicsUtilities contains a set of tools to perform common graphics operations easily. These operations are divided into several themes, listed below.

Compatible Images

Compatible images can, and should, be used to increase drawing performance. This class provides a number of methods to load compatible images directly from files or to convert existing images to compatibles images.

Creating Thumbnails

This class provides a number of methods to easily scale down images. Some of these methods offer a trade-off between speed and result quality and should be used all the time. They also offer the advantage of producing compatible images, thus automatically resulting into better runtime performance.

All these methods are both faster than Image.getScaledInstance(int, int, int) and produce better-looking results than the various drawImage() methods in Graphics, which can be used for image scaling.

Image Manipulation

This class provides two methods to get and set pixels in a buffered image. These methods try to avoid unmanaging the image in order to keep good performance.

  • Method Summary

    Modifier and Type Method Description
    static void clear​(java.awt.Image img)
    Clears the data from the image.
    static java.awt.image.BufferedImage convertToBufferedImage​(java.awt.Image img)
    Converts the specified image into a compatible buffered image.
    static java.awt.image.BufferedImage createColorModelCompatibleImage​(java.awt.image.BufferedImage image)
    Returns a new BufferedImage using the same color model as the image passed as a parameter.
    static java.awt.image.BufferedImage createCompatibleImage​(int width, int height)
    Returns a new opaque compatible image of the specified width and height.
    static java.awt.image.BufferedImage createCompatibleImage​(java.awt.image.BufferedImage image)
    Returns a new compatible image with the same width, height and transparency as the image specified as a parameter.
    static java.awt.image.BufferedImage createCompatibleImage​(java.awt.image.BufferedImage image, int width, int height)
    Returns a new compatible image of the specified width and height, and the same transparency setting as the image specified as a parameter.
    static java.awt.image.BufferedImage createCompatibleTranslucentImage​(int width, int height)
    Returns a new translucent compatible image of the specified width and height.
    static java.awt.image.BufferedImage createThumbnail​(java.awt.image.BufferedImage image, int newSize)
    Returns a thumbnail of a source image.
    static java.awt.image.BufferedImage createThumbnail​(java.awt.image.BufferedImage image, int newWidth, int newHeight)
    Returns a thumbnail of a source image.
    static java.awt.image.BufferedImage createThumbnailFast​(java.awt.image.BufferedImage image, int newSize)
    Returns a thumbnail of a source image.
    static java.awt.image.BufferedImage createThumbnailFast​(java.awt.image.BufferedImage image, int newWidth, int newHeight)
    Returns a thumbnail of a source image.
    static int[] getPixels​(java.awt.image.BufferedImage img, int x, int y, int w, int h, int[] pixels)
    Returns an array of pixels, stored as integers, from a BufferedImage.
    static java.awt.image.BufferedImage loadCompatibleImage​(java.io.InputStream in)
    Returns a new compatible image from a stream.
    static java.awt.image.BufferedImage loadCompatibleImage​(java.net.URL resource)
    Returns a new compatible image from a URL.
    static java.awt.Shape mergeClip​(java.awt.Graphics g, java.awt.Shape clip)
    Deprecated.
    static void setPixels​(java.awt.image.BufferedImage img, int x, int y, int w, int h, int[] pixels)
    Writes a rectangular area of pixels in the destination BufferedImage.
    static void tileStretchPaint​(java.awt.Graphics g, javax.swing.JComponent comp, java.awt.image.BufferedImage img, java.awt.Insets ins)
    Draws an image on top of a component by doing a 3x3 grid stretch of the image using the specified insets.
    static java.awt.image.BufferedImage toCompatibleImage​(java.awt.image.BufferedImage image)
    Return a new compatible image that contains a copy of the specified image.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait