Example usage for java.awt RenderingHints put

List of usage examples for java.awt RenderingHints put

Introduction

In this page you can find the example usage for java.awt RenderingHints put.

Prototype

public Object put(Object key, Object value) 

Source Link

Document

Maps the specified key to the specified value in this RenderingHints object.

Usage

From source file:util.ImgJaiTool.java

/**
 * A helper method that adds the tile cache hint with JAI.KEY_IMAGE_LAYOUT
 * to improve scale performance. This reduces the tile cache used to scale
 * the image./*from  w  w w  .ja  v a 2s. co  m*/
 * 
 * warning... seems to slow things down in some cases.
 * 
 * http://archives.java.sun.com/cgi-bin/wa?A2=ind0202&L=jai-interest&P=3228
 * 
 * @param hints
 *            existing list of RenderingHints
 * @param image
 *            image to scale
 * @param factX
 *            scaling factor x
 * @param factY
 *            scaling factor y
 */
protected static RenderingHints addScaleTileCacheHint(RenderingHints hints, RenderedOp image, float factX,
        float factY) {
    int tW = (int) (image.getTileWidth() * factX);
    int tH = (int) (image.getTileHeight() * factY);
    if (tW <= 0) {
        tW = 1;
    }
    if (tH <= 0) {
        tH = 1;
    }
    ImageLayout il = null;
    if (hints == null) {
        il = new ImageLayout().setTileWidth(tW).setTileHeight(tH);
        hints = new RenderingHints(JAI.KEY_IMAGE_LAYOUT, il);
    } else {
        il = (ImageLayout) hints.get(JAI.KEY_IMAGE_LAYOUT);
        if (il == null) {
            il = new ImageLayout();
        }
        il.setTileWidth(tW).setTileHeight(tH);
        hints.put(JAI.KEY_IMAGE_LAYOUT, il);
    }
    return hints;
}