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:net.algart.simagis.live.json.minimal.SimagisLiveUtils.java

private static BufferedImage toThumbnailSize(BufferedImage image) {
    final int w = image.getWidth();
    final int h = image.getHeight();
    final int max = Math.max(w, h);
    if (max <= 256) {
        return image;
    }/*from w w w.j  ava 2s .  c o  m*/
    final double s = max / 256d;
    final BufferedImage result = new BufferedImage(Math.max((int) Math.min(w / s, 256), 1),
            Math.max((int) Math.min(h / s, 256), 1), BufferedImage.TYPE_INT_BGR);
    final Graphics2D graphics = result.createGraphics();
    try {
        graphics.drawImage(image.getScaledInstance(result.getWidth(), result.getHeight(), Image.SCALE_SMOOTH),
                0, 0, null);
    } finally {
        graphics.dispose();
    }
    return result;
}

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

/**
 * Crops the image to the given size starting at (0,0)
 * //from  w  w w .  j  a  v a2  s .co  m
 * @param image
 *            The image to crop
 * @param width
 *            width in pixels
 * @param height
 *            height in pixels
 */
private static BufferedImage cropImage(BufferedImage image, int width, int height) {
    if (image.getWidth() == width && image.getHeight() == height) {
        return image;
    }
    return image.getSubimage(0, 0, width, height);
}

From source file:ImageProcessing.ImageProcessing.java

public static void processGrayscale(BufferedImage image) {
    //Converts a color image to a Grayscale image.
    for (int i = 0; i < image.getHeight(); i++) {
        for (int j = 0; j < image.getWidth(); j++) {
            int rgb = image.getRGB(j, i);
            Color currentPixel = new Color(rgb, true);
            //Find the average from all the color components for the given pixel.
            int grayLevel = (currentPixel.getRed() + currentPixel.getGreen() + currentPixel.getBlue()) / 3;

            int gray = (grayLevel << 16) + (grayLevel << 8) + grayLevel;
            image.setRGB(j, i, gray);/*from  w w  w. j av  a  2s .co m*/
        }
    }
}

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

public static BufferedImage scaleImage(BufferedImage image, double widthPerCent, double heightPerCent) {
    int w = (int) (image.getWidth() * widthPerCent);
    int h = (int) (image.getHeight() * heightPerCent);
    int t = image.getType();

    Image scaledImage = image.getScaledInstance(w, h, Image.SCALE_SMOOTH);

    BufferedImage newImg = new BufferedImage(w, h, t);
    newImg.getGraphics().drawImage(scaledImage, 0, 0, null);

    return newImg;
}

From source file:it.smartcommunitylab.parking.management.web.manager.MarkerIconStorage.java

private static BufferedImage changeColor(BufferedImage image, Color mask, Color replacement) {
    BufferedImage destImage = new BufferedImage(image.getWidth(), image.getHeight(),
            BufferedImage.TYPE_INT_ARGB);

    Graphics2D g = destImage.createGraphics();
    g.drawImage(image, null, 0, 0);// w ww  .j  ava  2  s.c o  m
    g.dispose();

    for (int i = 0; i < destImage.getWidth(); i++) {
        for (int j = 0; j < destImage.getHeight(); j++) {

            int destRGB = destImage.getRGB(i, j);

            if (matches(mask.getRGB(), destRGB)) {
                int rgbnew = getNewPixelRGB(replacement.getRGB(), destRGB);
                destImage.setRGB(i, j, rgbnew);
            }
        }
    }

    return destImage;
}

From source file:org.jamwiki.utils.ImageUtil.java

/**
 *
 *///from w  w w .  ja  v  a  2 s .  c om
private static void setScaledDimensions(BufferedImage bufferedImage, WikiImage wikiImage, int maxDimension) {
    int width = bufferedImage.getWidth();
    int height = bufferedImage.getHeight();
    if (width >= height) {
        height = (int) Math.floor(((double) maxDimension / (double) width) * (double) height);
        width = maxDimension;
    } else {
        width = (int) Math.floor(((double) maxDimension / (double) height) * (double) width);
        height = maxDimension;
    }
    wikiImage.setWidth(width);
    wikiImage.setHeight(height);
}

From source file:com.ables.pix.utility.PictureOps.java

public static BufferedImage tilt(BufferedImage image, double rotation) {
    double sin = Math.abs(Math.sin(getAngle()));
    double cos = Math.abs(Math.cos(getAngle()));
    int w = image.getWidth(), h = image.getHeight();

    int neww = (int) Math.floor(w * cos + sin * h), newh = (int) Math.floor(h * cos + sin * w);
    GraphicsConfiguration gc = getDefaultConfiguration();
    BufferedImage rotated = gc.createCompatibleImage(neww, newh);
    Graphics2D g = rotated.createGraphics();
    g.translate((neww - w) / 2, (newh - h / 2));
    g.rotate(getAngle(), w / 2, h / 2);/*from  w  w  w  .j  a  v  a  2  s.com*/
    g.drawRenderedImage(image, null);
    g.dispose();
    return rotated;
}

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

/**
 * Check canvas sizes and resize images to same size
 * //  w ww.ja  va 2s .  c o  m
 * @return true/false
 */
public static boolean imagesSameSize(BufferedImage image1, BufferedImage image2) {
    return (image1.getWidth() == image2.getWidth() && image1.getHeight() == image2.getHeight());
}

From source file:es.logongas.util.seguridad.CodigoVerificacionSeguro.java

/**
 * Esta funcin se aplica pq para imagenes muy grandes no reconoce el cdigo
 * QR/* w  w  w.j  av  a 2  s. co  m*/
 *
 * @param originalImage La imagen original
 * @param f El factor de escalado
 * @return La iamgen reescalada.
 */
private static BufferedImage resizeImage(BufferedImage originalImage, double f) {
    int ancho = (int) (((double) originalImage.getWidth()) * f);
    int alto = (int) (((double) originalImage.getHeight()) * f);
    int type = originalImage.getType() == 0 ? BufferedImage.TYPE_INT_ARGB : originalImage.getType();
    BufferedImage resizedImage = new BufferedImage(ancho, alto, type);
    Graphics2D g = resizedImage.createGraphics();
    g.drawImage(originalImage, 0, 0, ancho, alto, null);
    g.dispose();

    return resizedImage;
}

From source file:com.sketchy.utils.image.SketchyImage.java

public static BufferedImage toByteImage(BufferedImage image) {
    BufferedImage newImage = createByteImage(image.getWidth(), image.getHeight());
    Graphics2D graphics = newImage.createGraphics();
    graphics.setBackground(Color.white);
    graphics.fillRect(0, 0, image.getWidth(), image.getHeight());
    graphics.drawImage(image, 0, 0, null);
    return newImage;
}