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.reydentx.core.common.PhotoUtils.java

public static byte[] converImagePNGtoJPEG(InputStream data) {
    byte[] imageFinal = null;
    try {/*from  w  ww.j a va2 s .c o m*/
        ByteArrayOutputStream outstream = new ByteArrayOutputStream();
        BufferedImage bufferedImage = ImageIO.read(data);

        // create a blank, RGB, same width and height, and a white background
        BufferedImage newBufferedImage = new BufferedImage(bufferedImage.getWidth(), bufferedImage.getHeight(),
                BufferedImage.TYPE_INT_RGB);
        newBufferedImage.createGraphics().drawImage(bufferedImage, 0, 0, Color.WHITE, null);
        ImageIO.write(newBufferedImage, "JPEG", outstream);
        imageFinal = outstream.toByteArray();
        outstream.close();
    } catch (Exception ex) {
    }

    return imageFinal;
}

From source file:com.htmlhifive.pitalium.core.io.FilePersisterTest.java

static int[] toRGB(BufferedImage image) {
    return image.getRGB(0, 0, image.getWidth(), image.getHeight(), null, 0, image.getWidth());
}

From source file:cn.z.Ocr5.java

public static int getBlackCount(BufferedImage img) {
    final int width = img.getWidth();
    final int height = img.getHeight();
    int count = 0;
    for (int x = 0; x < width; ++x) {
        for (int y = 0; y < height; ++y) {
            if (CommonUtil.isWhite(img.getRGB(x, y), whiteThreshold) == 0) {
                count++;//w  ww . j a  v  a2  s. c o m
            }
        }
    }
    return count;
}

From source file:cz.cas.lib.proarc.common.imports.TiffImporter.java

private static BufferedImage scale(BufferedImage tiff, ScalingMethod method, Integer maxWidth,
        Integer maxHeight) {//from  w ww.  j a v a2s .co m

    long start = System.nanoTime();
    int height = tiff.getHeight();
    int width = tiff.getWidth();
    int targetWidth = width;
    int targetHeight = height;
    double scale = Double.MAX_VALUE;
    if (maxHeight != null && height > maxHeight) {
        scale = (double) maxHeight / height;
    }
    if (maxWidth != null && width > maxWidth) {
        double scalew = (double) maxWidth / width;
        scale = Math.min(scale, scalew);
    }
    if (scale != Double.MAX_VALUE) {
        targetHeight = (int) (height * scale);
        targetWidth = (int) (width * scale);
    }
    BufferedImage scaled = ImageSupport.scale(tiff, targetWidth, targetHeight, method, true);
    LOG.fine(String.format("scaled [%s, %s] to [%s, %s], boundary [%s, %s] [w, h], time: %s ms", width, height,
            targetWidth, targetHeight, maxWidth, maxHeight, (System.nanoTime() - start) / 1000000));
    return scaled;
}

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

/**
 * Combine a list of images horizontally into one new image.
 * //from w w  w .  ja v a 2s .  co  m
 * @param images The list of images to be combined
 * @return A new image, as wide horizontally as the sum of the input images,
 * containing all the input images
 */
public static BufferedImage combineImagesHorizontal(List<BufferedImage> images) {
    int imageType = -1;
    int height = 0;
    int width = 0;

    // first work out the sizing and image type, we assume the images
    // are all compatible.

    for (BufferedImage image : images) {
        if (imageType == -1) {
            imageType = image.getType();
        }

        width += image.getWidth();

        height = Math.max(height, image.getHeight());
    }

    // create the new image and clear it to black

    BufferedImage bi = new BufferedImage(width, height, imageType);

    Graphics2D g = bi.createGraphics();
    g.setColor(Color.BLACK);
    g.fillRect(0, 0, width, height);

    // merge the images into the new one

    int xpos = 0;

    for (BufferedImage image : images) {
        int ypos = (height - image.getHeight()) / 2;

        g.drawImage(image, xpos, ypos, null);

        xpos += image.getWidth();
    }

    return bi;
}

From source file:cn.z.Ocr5.java

public static boolean isNotEight(BufferedImage img) {
    final int width = img.getWidth();
    final int height = img.getHeight();
    int minCount = width;
    for (int y = height / 2 - 2; y < height / 2 + 2; ++y) {
        int count = 0;
        for (int x = 0; x < width / 2 + 2; ++x) {
            if (CommonUtil.isWhite(img.getRGB(x, y), whiteThreshold) == 0) {
                count++;/*  w w w  . ja  va 2  s.co  m*/
            }
        }
        minCount = Math.min(count, minCount);
    }
    return minCount < 2;
}

From source file:cn.z.Ocr5.java

public static boolean isNotThree(BufferedImage img) {
    final int width = img.getWidth();
    final int height = img.getHeight();
    int minCount = width;
    for (int y = height / 2 - 3; y < height / 2 + 3; ++y) {
        int count = 0;
        for (int x = 0; x < width / 2 + 1; ++x) {
            if (CommonUtil.isWhite(img.getRGB(x, y), whiteThreshold) == 0) {
                count++;// ww w .ja v  a2s  .  c om
            }
        }
        minCount = Math.min(count, minCount);
    }
    return minCount > 0;
}

From source file:cn.z.Ocr5.java

public static boolean isNotFive(BufferedImage img) {
    final int width = img.getWidth();
    final int height = img.getHeight();
    int minCount = width;
    for (int y = 0; y < height / 3; ++y) {
        int count = 0;
        for (int x = width * 2 / 3; x < width; ++x) {
            if (CommonUtil.isWhite(img.getRGB(x, y), whiteThreshold) == 0) {
                count++;/*  w  w  w  . j a v  a2s.c  o  m*/
            }
        }
        minCount = Math.min(count, minCount);
    }
    return minCount > 0;
}

From source file:GraphicsUtil.java

public static void drawImage(Graphics g, BufferedImage img, Rectangle2D bounds, ImageObserver observer) {
    Graphics2D g2 = (Graphics2D) g;
    g2.drawImage(img, // what to draw
            (int) bounds.getMinX(), // dest left
            (int) bounds.getMinY(), // dest top
            (int) bounds.getMaxX(), // dest right
            (int) bounds.getMaxY(), // dest bottom
            0, // src left
            0, // src top
            img.getWidth(), // src right
            img.getHeight(), // src bottom
            observer // to notify of image updates
    );/* ww w.  j  a va2  s  .co  m*/
}

From source file:de.mprengemann.intellij.plugin.androidicons.images.ImageUtils.java

private static BufferedImage resizeNormalImage(BufferedImage image, ImageInformation information)
        throws IOException {
    int originalWidth = image.getWidth();
    int originalHeight = image.getHeight();
    if (originalHeight == information.getTargetHeight() && originalWidth == information.getTargetWidth()
            && MathUtils.floatEquals(information.getFactor(), 1f)) {
        return image;
    }//from www . j  a va2  s  . c  o m

    int newWidth = information.getTargetWidth();
    int newHeight = information.getTargetHeight();
    if (newWidth <= 0 || newHeight <= 0) {
        newWidth = originalWidth;
        newHeight = originalHeight;
    }

    if (information.getFactor() >= 0) {
        newWidth = (int) (newWidth * information.getFactor());
        newHeight = (int) (newHeight * information.getFactor());
    }

    return resizeNormalImage(image, newWidth, newHeight, information);
}