Example usage for java.awt.image BufferedImage getHeight

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

Introduction

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

Prototype

public int getHeight() 

Source Link

Document

Returns the height of the BufferedImage .

Usage

From source file:com.uksf.mf.core.utility.loaders.ImageLoad.java

/**
 * Changes colour of all non-transparent pixels for given image to given colour
 * @param image - image to change colours in
 * @param newColour colour to change to/*from   w  w  w  .  ja  v  a2  s. com*/
 * @return image with changed colours
 */
private static ImageIcon changeImageColour(ImageIcon image, int newColour) {
    LogHandler.logSeverity(INFO, "Converting image: " + image + " colour to: " + newColour);
    BufferedImage bufferedImage = new BufferedImage(image.getIconWidth(), image.getIconHeight(),
            BufferedImage.TYPE_INT_ARGB);
    Graphics graphics = bufferedImage.createGraphics();
    image.paintIcon(null, graphics, 0, 0);
    graphics.dispose();
    for (int x = 0; x < bufferedImage.getWidth(); x++) {
        for (int y = 0; y < bufferedImage.getHeight(); y++) {
            int colour = bufferedImage.getRGB(x, y);
            colour = (((colour >> 24) & 0xff) << 24) | (((colour & 0x00ff0000) >> 16) << 16)
                    | (((colour & 0x0000ff00) >> 8) << 8) | (colour & 0x000000ff);
            if (colour != COLOUR_TRANSPARENT.getRGB()) {
                newColour = (((colour >> 24) & 0xff) << 24) | (((newColour & 0x00ff0000) >> 16) << 16)
                        | (((newColour & 0x0000ff00) >> 8) << 8) | (newColour & 0x000000ff);
                bufferedImage.setRGB(x, y, newColour);
            }
        }
    }
    return new ImageIcon(bufferedImage);
}

From source file:common.utils.ImageUtils.java

/**
*    ?  ?/* w  w w .  j  a v a 2  s.c  om*/
* @param scaling scaling
* @param image picture
 * @return  ?
 */
public static Dimension getDimmension(double scaling, BufferedImage image) {
    return new Dimension((int) (scaling * image.getWidth()), (int) (scaling * image.getHeight()));
}

From source file:com.afis.jx.ckfinder.connector.utils.ImageUtils.java

/**
 * creates dimension of thumb.// www  . j av  a 2s .c o m
 *
 * @param image original image.
 * @param maxWidth max thumb width
 * @param maxHeight max thumb height
 * @return dimension of thumb image.
 */
private static Dimension createThumbDimension(final BufferedImage image, final int maxWidth,
        final int maxHeight) {
    Dimension dimension = new Dimension();
    if (image.getWidth() >= image.getHeight()) {
        if (image.getWidth() >= maxWidth) {
            dimension.width = maxWidth;
            dimension.height = Math.round(((float) maxWidth / image.getWidth()) * image.getHeight());
        } else {
            dimension.height = image.getHeight();
            dimension.width = image.getWidth();
        }
    } else {
        if (image.getHeight() >= maxHeight) {
            dimension.height = maxHeight;
            dimension.width = Math.round((((float) maxHeight / image.getHeight()) * image.getWidth()));
        } else {
            dimension.height = image.getHeight();
            dimension.width = image.getWidth();
        }
    }
    return dimension;
}

From source file:ml.hsv.java

public static hsv[][] img2RGB2HSV(String ip) throws IOException {
    BufferedImage image;
    int width, height;

    File input = new File(ip);
    image = ImageIO.read(input);/*from  w ww  . ja  va2s . c  o  m*/
    width = image.getWidth();
    height = image.getHeight();

    hsv hsvImage[][] = new hsv[height][width];

    for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
            Color c = new Color(image.getRGB(j, i));
            hsvImage[i][j] = new hsv(c.getRed(), c.getGreen(), c.getBlue());
        }
    }

    HSV2File(hsvImage, width, height);

    return hsvImage;
}

From source file:ml.hsv.java

public static hsv[][] img2RGB2HSV(File input) throws IOException {
    BufferedImage image;
    int width, height;

    // File input = new File(ip);
    image = ImageIO.read(input);//from w ww  .j  a  v a 2  s .c  o m
    width = image.getWidth();
    height = image.getHeight();

    hsv hsvImage[][] = new hsv[height][width];

    for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
            Color c = new Color(image.getRGB(j, i));
            hsvImage[i][j] = new hsv(c.getRed(), c.getGreen(), c.getBlue());
        }
    }
    // HSV2File(hsvImage,width,height); debugging code removed      
    return hsvImage;
}

From source file:ch.rasc.downloadchart.DownloadChartServlet.java

private static Dimension calculateDimension(BufferedImage image, Integer width, Integer height) {

    int imgWidth = image.getWidth();
    int imgHeight = image.getHeight();

    if (width == null && height != null) {
        return new Dimension(imgWidth * height / imgHeight, height);
    } else if (width != null && height == null) {
        return new Dimension(width, imgHeight * width / imgWidth);
    } else if (width != null && height != null) {
        return new Dimension(width, height);
    }// w  w w . ja  va2 s.co  m

    return null;

}

From source file:com.smash.revolance.ui.model.helper.ImageHelper.java

public static BufferedImage cropImage(final BufferedImage img, int x, int y, int w, int h, double xScale,
        double yScale) {
    x = (int) (x * xScale);
    w = (int) (w * xScale);

    y = (int) (y * yScale);
    h = (int) (h * yScale);

    if (img.getHeight() < (y + h)) {
        h = img.getHeight() - y;//w w w.j  a  va 2s  .c o  m
    }
    if (img.getWidth() < (x + w)) {
        w = img.getWidth() - x;
    }

    return img.getSubimage(x, y, w, h);
}

From source file:ImageProcessing.ImageProcessing.java

public static void copyImage(BufferedImage source_image, BufferedImage target_image) {
    //Copies pixel data from source image to target image.
    //The size will not be copied/adjusted, so keep in mind the size of both images.
    for (int i = 0; i < target_image.getHeight(); i++) {
        for (int j = 0; j < target_image.getWidth(); j++) {
            int rgb = source_image.getRGB(j, i);
            target_image.setRGB(j, i, rgb);
        }/*from  w  w  w  .  j a v a 2  s  .  c  o m*/
    }
}

From source file:com.vaadin.testbench.screenshot.ImageUtil.java

/**
 * Resize images to be same size. The size is determined by the minimum
 * height and minimum width of the images.
 * /*ww  w  . ja  v a  2 s . c  o m*/
 * @param image1
 *            an image.
 * @param image2
 *            an image.
 * @return a list containing two images with the same dimensions
 */
public static List<BufferedImage> cropToBeSameSize(BufferedImage image1, BufferedImage image2) {
    if (imagesSameSize(image1, image2)) {
        return Arrays.asList(image1, image2);
    }

    int minHeight = Math.min(image1.getHeight(), image2.getHeight());
    int minWidth = Math.min(image1.getWidth(), image2.getWidth());

    BufferedImage cropped1 = cropImage(image1, minWidth, minHeight);
    BufferedImage cropped2 = cropImage(image2, minWidth, minHeight);
    return Arrays.asList(cropped1, cropped2);
}

From source file:com.alvermont.terraj.stargen.ui.UIUtils.java

/**
 * Scale an image to a particular X and Y size in pixels
 * // www. ja  v  a2  s . c o m
 * @param image The image to be scaled
 * @param pixelsX The desired horizontal size in pixels
 * @param pixelsY The desired vertical size in pixels
 * @return A new image scaled to the requested dimensions
 */
public static BufferedImage scaleImage(BufferedImage image, int pixelsX, int pixelsY) {
    int actualWidth = image.getWidth();
    int actualHeight = image.getHeight();

    // work out the scale factor

    double sx = (float) (pixelsX) / actualWidth;
    double sy = (float) (pixelsY) / actualHeight;

    BufferedImage nbi = new BufferedImage(pixelsX, pixelsY, image.getType());

    Graphics2D g2 = nbi.createGraphics();
    AffineTransform at = AffineTransform.getScaleInstance(sx, sy);

    g2.setTransform(at);

    g2.drawImage(image, 0, 0, null);

    return nbi;
}