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.uwsoft.editor.proxy.ResolutionManager.java

public static BufferedImage imageResize(File file, float ratio) {
    BufferedImage destinationBufferedImage = null;
    try {/*  ww  w  .  j a  v  a 2s. c o  m*/
        BufferedImage sourceBufferedImage = ImageIO.read(file);
        if (ratio == 1.0) {
            return sourceBufferedImage;
        }
        // When image has to be resized smaller then 3 pixels we should leave it as is, as to ResampleOP limitations
        // But it should also trigger a warning dialog at the and of the import, to notify the user of non resized images.
        if (sourceBufferedImage.getWidth() * ratio < 3 || sourceBufferedImage.getHeight() * ratio < 3) {
            return null;
        }
        int newWidth = Math.max(3, Math.round(sourceBufferedImage.getWidth() * ratio));
        int newHeight = Math.max(3, Math.round(sourceBufferedImage.getHeight() * ratio));
        String name = file.getName();
        Integer[] patches = null;
        if (name.endsWith(EXTENSION_9PATCH)) {
            patches = NinePatchUtils.findPatches(sourceBufferedImage);
            sourceBufferedImage = NinePatchUtils.removePatches(sourceBufferedImage);

            newWidth = Math.round(sourceBufferedImage.getWidth() * ratio);
            newHeight = Math.round(sourceBufferedImage.getHeight() * ratio);
            System.out.println(sourceBufferedImage.getWidth());

            destinationBufferedImage = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_ARGB);
            Graphics2D g2 = destinationBufferedImage.createGraphics();
            g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                    RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
            g2.drawImage(sourceBufferedImage, 0, 0, newWidth, newHeight, null);
            g2.dispose();

        } else {
            // resize with bilinear filter
            ResampleOp resampleOp = new ResampleOp(newWidth, newHeight);
            destinationBufferedImage = resampleOp.filter(sourceBufferedImage, null);
        }

        if (patches != null) {
            destinationBufferedImage = NinePatchUtils.convertTo9Patch(destinationBufferedImage, patches, ratio);
        }

    } catch (IOException ignored) {

    }

    return destinationBufferedImage;
}

From source file:gr.iti.mklab.reveal.forensics.util.Util.java

public static float[][][] getImageDifference(BufferedImage image1, BufferedImage image2) {
    Color tmpColor1, tmpColor2;//from   w w  w  . j  a  va2 s  . co  m
    int width = image1.getWidth();
    int height = image1.getHeight();
    float[][][] outputMap = new float[3][width][height];
    for (int ii = 0; ii < width; ii++) {
        for (int jj = 0; jj < height; jj++) {
            tmpColor1 = new Color(image1.getRGB(ii, jj));
            tmpColor2 = new Color(image2.getRGB(ii, jj));
            outputMap[0][ii][jj] = (float) (tmpColor1.getRed() - tmpColor2.getRed())
                    * (tmpColor1.getRed() - tmpColor2.getRed());
            outputMap[1][ii][jj] = (float) (tmpColor1.getGreen() - tmpColor2.getGreen())
                    * (tmpColor1.getGreen() - tmpColor2.getGreen());
            outputMap[2][ii][jj] = (float) (tmpColor1.getBlue() - tmpColor2.getBlue())
                    * (tmpColor1.getBlue() - tmpColor2.getBlue());
        }
    }
    return outputMap;
}

From source file:gr.iti.mklab.reveal.forensics.util.Util.java

public static double[][][] getImageDifferenceD(BufferedImage image1, BufferedImage image2) {
    Color tmpColor1, tmpColor2;/*from   w  ww  . j ava  2 s  .  co  m*/
    int width = image1.getWidth();
    int height = image1.getHeight();
    double red_temp, green_temp, blue_temp;

    double[][][] outputMap = new double[3][width][height];
    for (int ii = 0; ii < width; ii++) {
        for (int jj = 0; jj < height; jj++) {
            tmpColor1 = new Color(image1.getRGB(ii, jj));
            tmpColor2 = new Color(image2.getRGB(ii, jj));
            red_temp = tmpColor1.getRed() - tmpColor2.getRed();
            green_temp = tmpColor1.getGreen() - tmpColor2.getGreen();
            blue_temp = tmpColor1.getBlue() - tmpColor2.getBlue();
            outputMap[0][ii][jj] = (double) (red_temp) * (red_temp);
            outputMap[1][ii][jj] = (double) (green_temp) * (green_temp);
            outputMap[2][ii][jj] = (double) (blue_temp) * (blue_temp);
        }
    }
    return outputMap;
}

From source file:com.actelion.research.orbit.imageAnalysis.utils.ImageUtils.java

/**
 * Returns min and max intensities and percentiles 0.01, 0.05, 0.1, 0.9, 0.95, 0.99 of a BufferedImage.
 *
 * @param image/* w  w w .  java  2 s.com*/
 * @return
 */
public static int[][] getMinMaxIntensitiesOfBI(BufferedImage image) {
    WritableRaster raster = image.getRaster();
    // per band: { min, 1%, 5%, 10%, 90%, 95%, 99%, max }
    int[][] intensities = new int[raster.getNumBands()][8];

    DescriptiveStatistics[] ds = new DescriptiveStatistics[raster.getNumBands()];
    for (int i = 0; i < raster.getNumBands(); i++)
        ds[i] = new DescriptiveStatistics();

    int width = image.getWidth();
    int height = image.getHeight();

    for (int row = 0; row < height; row++) {
        for (int col = 0; col < width; col++) {
            for (int band = 0; band < raster.getNumBands(); band++) {
                ds[band].addValue(raster.getSample(col, row, band));
            }
        }
    }

    for (int i = 0; i < ds.length; i++) {
        intensities[i][0] = (int) ds[i].getMin();
        intensities[i][1] = (int) ds[i].getPercentile(1);
        intensities[i][2] = (int) ds[i].getPercentile(5);
        intensities[i][3] = (int) ds[i].getPercentile(10);
        intensities[i][4] = (int) ds[i].getPercentile(90);
        intensities[i][5] = (int) ds[i].getPercentile(95);
        intensities[i][6] = (int) ds[i].getPercentile(99);
        intensities[i][7] = (int) ds[i].getMax();
    }
    return intensities;
}

From source file:edu.stanford.epad.common.pixelmed.TIFFMasksToDSOConverter.java

public static BufferedImage convertRGBAToIndexed(BufferedImage src) {
    BufferedImage dest = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_BYTE_INDEXED);

    dest.createGraphics().drawImage(src, 0, 0, null);
    return dest;//from  ww  w  .  j a  v  a 2s .  c  om
}

From source file:edu.ku.brc.ui.GraphicsUtils.java

/**
 * @param orig the original image/*from   w w w . j  a va  2s  .com*/
 * @param maxHeight the max height of the scaled image
 * @param maxWidth the max width of the scaled image
 * @param preserveAspectRatio if true, the scaling preserves the aspect ratio of the original image
 * @param doHighQuality do higher quality thumbnail (slow)
 * @return the byte array of the scaled image
 * @throws IOException an error occurred while encoding the result as a JPEG image
 */
public static byte[] scaleImage(final BufferedImage orig, final int maxHeight, final int maxWidth,
        final boolean preserveAspectRatio, boolean doHighQuality) throws IOException {
    BufferedImage scaled;
    if (true) {
        int targetW = maxWidth;
        int targetH = maxHeight;

        if (preserveAspectRatio) {
            int origWidth = orig.getWidth();
            int origHeight = orig.getHeight();

            double origRatio = (double) origWidth / (double) origHeight;
            double scaledRatio = (double) maxWidth / (double) maxHeight;

            if (origRatio > scaledRatio) {
                targetH = (int) (targetW / origRatio);
            } else {
                targetW = (int) (targetH * origRatio);
            }
        }

        scaled = getScaledInstance(orig, targetW, targetH, doHighQuality);
    } else {
        scaled = generateScaledImage(orig, RenderingHints.VALUE_INTERPOLATION_BILINEAR,
                Math.max(maxHeight, maxWidth));
    }

    ByteArrayOutputStream output = new ByteArrayOutputStream(8192);

    ImageIO.write(scaled, "jpeg", output);

    byte[] outputBytes = output.toByteArray();
    output.close();

    return outputBytes;
}

From source file:com.t3.persistence.PersistenceUtil.java

public static void saveToken(Token token, File file, boolean doWait) throws IOException {
    // Thumbnail/*from  w  ww . j  av  a 2s.  co m*/
    BufferedImage image = null;
    if (doWait)
        image = ImageManager.getImageAndWait(token.getImageAssetId());
    else
        image = ImageManager.getImage(token.getImageAssetId());

    Dimension sz = new Dimension(image.getWidth(), image.getHeight());
    SwingUtil.constrainTo(sz, 50);
    BufferedImage thumb = new BufferedImage(sz.width, sz.height, BufferedImage.TRANSLUCENT);
    Graphics2D g = thumb.createGraphics();
    g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    g.drawImage(image, 0, 0, sz.width, sz.height, null);
    g.dispose();

    PackedFile pakFile = null;
    try {
        pakFile = new PackedFile(file);
        saveAssets(token.getAllImageAssets(), pakFile);
        pakFile.putFile(Token.FILE_THUMBNAIL, ImageUtil.imageToBytes(thumb, "png"));
        pakFile.setContent(token);
        pakFile.save();
    } finally {
        if (pakFile != null)
            pakFile.close();
    }
}

From source file:ImageOpByRomain.java

/**
 * <p>/*from  w w  w  .  j a  va  2  s .co m*/
 * Returns a new compatible image with the same width, height and transparency
 * as the image specified as a parameter.
 * </p>
 * 
 * @see java.awt.Transparency
 * @see #createCompatibleImage(int, int)
 * @see #createCompatibleImage(java.awt.image.BufferedImage, int, int)
 * @see #createTranslucentCompatibleImage(int, int)
 * @see #loadCompatibleImage(java.net.URL)
 * @see #toCompatibleImage(java.awt.image.BufferedImage)
 * @param image
 *            the reference image from which the dimension and the
 *            transparency of the new image are obtained
 * @return a new compatible <code>BufferedImage</code> with the same
 *         dimension and transparency as <code>image</code>
 */
public static BufferedImage createCompatibleImage(BufferedImage image) {
    return createCompatibleImage(image, image.getWidth(), image.getHeight());
}

From source file:cognitivej.vision.overlay.builder.ImageOverlayBuilder.java

@NotNull
private static BufferedImage copy(@NotNull BufferedImage img, int imageType) {
    int width = img.getWidth();
    int height = img.getHeight();

    BufferedImage newImage = new BufferedImage(width, height, imageType);
    Graphics g = newImage.createGraphics();
    g.drawImage(img, 0, 0, null);/*from   w  w  w. j a  va 2s . c  o m*/
    g.dispose();

    return newImage;
}

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

public static BufferedImage resizeNinePatchImage(ImageInformation information) throws IOException {
    BufferedImage image = ImageIO.read(information.getImageFile());
    if (MathUtils.floatEquals(information.getFactor(), 1f)) {
        return image;
    }/*from w w w  .  j a v  a2  s . c o m*/

    BufferedImage trimmedImage = trim9PBorder(image);
    ImageInformation trimmedImageInformation = ImageInformation.newBuilder(information)
            .setExportName(getExportName("trimmed", information.getExportName())).build();
    saveImageTempFile(trimmedImage, trimmedImageInformation);
    trimmedImage = resizeNormalImage(trimmedImage, trimmedImageInformation);
    saveImageTempFile(trimmedImage, ImageInformation.newBuilder(trimmedImageInformation)
            .setExportName(getExportName("trimmedResized", information.getExportName())).build());

    BufferedImage borderImage;

    int w = trimmedImage.getWidth();
    int h = trimmedImage.getHeight();

    try {
        borderImage = generateBordersImage(image, w, h);
    } catch (Exception e) {
        return null;
    }

    int[] rgbArray = new int[w * h];
    trimmedImage.getRGB(0, 0, w, h, rgbArray, 0, w);
    borderImage.setRGB(1, 1, w, h, rgbArray, 0, w);

    return borderImage;
}