Example usage for java.awt.image RenderedImage getHeight

List of usage examples for java.awt.image RenderedImage getHeight

Introduction

In this page you can find the example usage for java.awt.image RenderedImage getHeight.

Prototype

int getHeight();

Source Link

Document

Returns the height of the RenderedImage.

Usage

From source file:pcgen.gui2.tools.Utility.java

/**
 * Adjust the crop rectangle to fit within the image it is cropping. Also
 * ensure the area is square.//w  w  w.j  av  a2 s  . co  m
 *
 * @param image    The image being cropped
 * @param cropRect The rectangle defining the cropping area. This may be updated.
 */
public static void adjustRectToFitImage(RenderedImage image, Rectangle cropRect) {
    // Make sure the rectangle is not too big
    if (cropRect.width > image.getWidth()) {
        cropRect.width = image.getWidth();
    }
    if (cropRect.height > image.getHeight()) {
        cropRect.height = image.getHeight();
    }

    // Make it square
    int dimension = Math.min(cropRect.width, cropRect.height);
    cropRect.setSize(dimension, dimension);

    // Now adjust the origin point so the box is within the image 
    if ((cropRect.x + cropRect.width) > image.getWidth()) {
        cropRect.x = image.getWidth() - cropRect.width;
    }
    if ((cropRect.y + cropRect.height) > image.getHeight()) {
        cropRect.y = image.getHeight() - cropRect.height;
    }
}