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:exemplos.PegandoPixelsSemJAI.java

public void pegaPixel() throws IOException {

    File f = new File("D:\\ProjetosNetBeans\\PDI\\src\\imagens\\ebola.png"); //seleciona o arquivo
    BufferedImage image = ImageIO.read(f); //le o arquivo
    System.out.println("Dimenses: " + image.getWidth() + "x" + image.getHeight() + "pixels"); //exibe suas dimenses

    Raster raster = image.getRaster(); //pega os valores dos pixels
    double pixel[] = new double[3]; //cria um array com 3 posies
    int brancos = 0; //cria uma varivel para contar os pixels brancos
    for (int h = 0; h < image.getHeight(); h++)
        for (int w = 0; w < image.getWidth(); w++) {
            raster.getPixel(w, h, pixel);
            if ((pixel[0] == 255) && (pixel[1] == 255) && (pixel[2] == 255))//confirma se o RGB  igual a 255, ou seja, branco
                brancos++;//from w  w  w . j  ava 2  s  .  co  m

        }

}

From source file:org.shredzone.cilla.service.resource.ImageTools.java

/**
 * Analyzes the dimension of the given image {@link DataSource}.
 *
 * @param src//from  ww w  .  java  2  s .  co m
 *            {@link DataSource} to analyze
 * @return image dimensions
 */
public Dimension analyzeDimension(DataSource src) throws CillaServiceException {
    try {
        BufferedImage image = ImageIO.read(src.getInputStream());
        return (image != null ? new Dimension(image.getWidth(), image.getHeight()) : null);
    } catch (IOException ex) {
        throw new CillaServiceException(ex);
    }
}

From source file:com.webpagebytes.cms.DefaultImageProcessor.java

public boolean resizeImage(WPBFileStorage cloudStorage, WPBFilePath cloudFile, int desiredSize,
        String outputFormat, OutputStream os) throws WPBException {
    InputStream is = null;/*from w ww  .j  a v  a 2 s . c  om*/
    try {
        //get the file content
        WPBFileInfo fileInfo = cloudStorage.getFileInfo(cloudFile);
        String type = fileInfo.getContentType().toLowerCase();
        if (!type.startsWith("image")) {
            return false;
        }
        is = cloudStorage.getFileContent(cloudFile);
        BufferedImage bufImg = ImageIO.read(is);
        Dimension<Integer> newSize = getResizeSize(bufImg.getWidth(), bufImg.getHeight(), desiredSize);
        BufferedImage bdest = new BufferedImage(newSize.getX(), newSize.getY(), BufferedImage.TYPE_INT_RGB);
        Graphics2D g = bdest.createGraphics();
        Dimension<Double> scale = getResizeScale(bufImg.getHeight(), bufImg.getWidth(), desiredSize);
        AffineTransform at = AffineTransform.getScaleInstance(scale.getX(), scale.getY());
        g.drawRenderedImage(bufImg, at);
        ImageIO.write(bdest, outputFormat, os);
        return true;
    } catch (Exception e) {
        throw new WPBException("Cannot resize image ", e);
    } finally {
        IOUtils.closeQuietly(is);
    }

}

From source file:ImageOpByRomain.java

/**
 * <p>//  w w w. ja v a2s .co  m
 * Return a new compatible image that contains a copy of the specified image.
 * This method ensures an image is compatible with the hardware, and therefore
 * optimized for fast blitting operations.
 * </p>
 * 
 * @see #createCompatibleImage(java.awt.image.BufferedImage)
 * @see #createCompatibleImage(java.awt.image.BufferedImage, int, int)
 * @see #createCompatibleImage(int, int)
 * @see #createTranslucentCompatibleImage(int, int)
 * @see #loadCompatibleImage(java.net.URL)
 * @param image
 *            the image to copy into a new compatible image
 * @return a new compatible copy, with the same width and height and
 *         transparency and content, of <code>image</code>
 */
public static BufferedImage toCompatibleImage(BufferedImage image) {
    if (image.getColorModel().equals(CONFIGURATION.getColorModel())) {
        return image;
    }

    BufferedImage compatibleImage = CONFIGURATION.createCompatibleImage(image.getWidth(), image.getHeight(),
            image.getTransparency());
    Graphics g = compatibleImage.getGraphics();
    g.drawImage(image, 0, 0, null);
    g.dispose();

    return compatibleImage;
}

From source file:csns.util.ImageUtils.java

public File resize(File file, int targetSize, boolean always) {
    File newFile = null;/*w  w  w  . j  a v  a 2  s.co  m*/

    try {
        BufferedImage image = ImageIO.read(fileIO.getDiskFile(file));

        if (!always && image.getWidth() < targetSize && image.getHeight() < targetSize)
            return file;

        BufferedImage newImage = Scalr.resize(image, targetSize);
        java.io.File tempFile = java.io.File.createTempFile("temp", null);
        ImageIO.write(newImage, "jpg", tempFile);

        newFile = new File();
        newFile.setName(file.getName() + "_" + targetSize + ".jpg");
        newFile.setType("image/jpeg");
        newFile.setSize(tempFile.length());
        newFile.setOwner(file.getOwner());
        newFile.setParent(file.getParent());
        newFile.setPublic(file.isPublic());
        newFile = fileDao.saveFile(newFile);

        tempFile.renameTo(fileIO.getDiskFile(newFile, false));
    } catch (IOException e) {
        logger.error("Fail to resize image " + file.getName(), e);
    }

    return newFile;
}

From source file:net.pkhsolutions.pecsapp.control.PictureTransformer.java

/**
 * TODO Document me//from   w  ww.j  a va  2s.  com
 *
 * @param image
 * @param maxHeightInPx
 * @param maxWidthInPx
 * @return
 */
@NotNull
public BufferedImage scaleIfNecessary(@NotNull BufferedImage image, int maxHeightInPx, int maxWidthInPx) {
    int w = image.getWidth();
    int h = image.getHeight();

    int newW;
    int newH;

    if (w <= maxWidthInPx && h <= maxHeightInPx) {
        return image;
    } else if (w > h) {
        newW = maxWidthInPx;
        newH = newW * h / w;
    } else {
        newH = maxHeightInPx;
        newW = newH * w / h;
    }
    LOGGER.info("Original size was w{} x h{}, new size is w{} x h{}", w, h, newW, newH);
    Image tmp = image.getScaledInstance(newW, newH, Image.SCALE_SMOOTH);
    BufferedImage img = new BufferedImage(newW, newH, image.getType());
    Graphics2D g2d = img.createGraphics();
    g2d.drawImage(tmp, 0, 0, null);
    g2d.dispose();
    return img;
}

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

public static float[][][] getResizedImageDifference(BufferedImage image1, BufferedImage image2, int newWidth,
        int newHeight) {
    // Calculate the subsampled difference between two buffered images
    float[][][] outputMap = new float[3][newWidth][newHeight];
    float widthModifier = (float) image1.getWidth() / newWidth;
    float heightModifier = (float) image1.getHeight() / newHeight;
    Color tmpColor1, tmpColor2;/*w w  w .jav a 2s .c  o m*/
    for (int ii = 0; ii < newHeight; ii++) {
        for (int jj = 0; jj < newWidth; jj++) {
            try {
                tmpColor1 = new Color(
                        image1.getRGB(Math.round(jj * widthModifier), Math.round(ii * heightModifier)));
                tmpColor2 = new Color(
                        image2.getRGB(Math.round(jj * widthModifier), Math.round(ii * heightModifier)));
                outputMap[0][jj][ii] = (float) (tmpColor1.getRed() - tmpColor2.getRed())
                        * (tmpColor1.getRed() - tmpColor2.getRed());
                outputMap[1][jj][ii] = (float) (tmpColor1.getGreen() - tmpColor2.getGreen())
                        * (tmpColor1.getGreen() - tmpColor2.getGreen());
                outputMap[2][jj][ii] = (float) (tmpColor1.getBlue() - tmpColor2.getBlue())
                        * (tmpColor1.getBlue() - tmpColor2.getBlue());
            } catch (Exception e) {
                System.out.println(newHeight + " " + newWidth + " " + image1.getHeight() + " "
                        + image1.getWidth() + " " + ii + " " + jj + " " + Math.round(ii * heightModifier) + " "
                        + Math.round(jj * widthModifier) + " " + heightModifier + " " + widthModifier);
                e.printStackTrace();
                return outputMap;
            }
        }
    }
    return outputMap;
}

From source file:edu.cornell.mannlib.vitro.webapp.controller.freemarker.ImageUploadThumbnailer.java

private String imageSize(BufferedImage image) {
    return image.getWidth() + " by " + image.getHeight();
}

From source file:net.sf.jabref.gui.PdfPreviewPanel.java

private BufferedImage resizeImage(BufferedImage originalImage, int width, int height, int type) {
    int h = originalImage.getHeight();
    int w = originalImage.getWidth();
    if ((height == 0) || (width == 0)) {
        height = h;/*from w w w . j a  v a  2 s  .co  m*/
        width = w;
    } else {
        float factorH = (float) height / (float) h;
        float factorW = (float) width / (float) w;

        if (factorH < factorW) {
            // use factorH, only width has to be changed as height is
            // already correct
            width = Math.round(w * factorH);
        } else {
            width = Math.round(h * factorW);
        }
    }

    BufferedImage resizedImage = new BufferedImage(width, height, type);
    Graphics2D g = resizedImage.createGraphics();
    g.drawImage(originalImage, 0, 0, width, height, null);
    return resizedImage;
}

From source file:com.alibaba.simpleimage.codec.jpeg.JPEGDecodePerformanceTest.java

protected void run(DecodeFacade decoder, File rootDir, String filename, int times, int frequency)
        throws Exception {
    long start, end, total = 0L;
    if (rootDir == null) {
        rootDir = imgDir;/*from  w w  w  .  j  ava  2 s. com*/
    }

    FileInputStream inputStream = new FileInputStream(new File(rootDir, filename));

    ByteArrayOutputStream temp = new ByteArrayOutputStream();
    IOUtils.copy(inputStream, temp);
    IOUtils.closeQuietly(inputStream);

    InputStream img = temp.toInputStream();
    temp = null;

    System.out.println("***********Performance Test**************");

    for (int i = 0; i < frequency; i++) {
        // System.gc();
        // Thread.sleep(5 * 1000L);

        start = System.currentTimeMillis();

        for (int t = 0; t < times; t++) {
            // File img = imgs[t % imgs.length];
            img.reset();
            BufferedImage bi = decoder.decode(img);
            bi.getHeight();
            bi = null;
        }

        end = System.currentTimeMillis();

        total += (end - start);
    }

    System.out.printf("Decoder : %s \n", decoder.getName());
    System.out.println("Image : " + filename);
    System.out.printf("Times : %d\n", times);
    System.out.printf("Frequency : %d\n", frequency);
    System.out.printf("Total time : %d ms\n", total);
    System.out.printf("Average time : %.2f ms\n", ((double) total / (times * frequency)));
}