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:de.fhg.igd.swingrcp.SwingRCPUtilities.java

/**
 * Applies the given transparency mask to a buffered image. Always creates a
 * new buffered image containing an alpha channel. Copies the old image into
 * the new one and then sets the alpha pixels according to the given mask.
 * /*from  w w w.j a  va  2s.c om*/
 * @param img the old image
 * @param mask the alpha mask
 * @return the new image with alpha channel applied
 * @throws IllegalArgumentException if the image's size does not match the
 *             mask's size
 */
public static BufferedImage applyTransparencyMask(BufferedImage img, ImageData mask) {
    if (mask.width != img.getWidth() || mask.height != img.getHeight()) {
        throw new IllegalArgumentException("Image size does not match the mask size");
    }

    // copy image and also convert to RGBA
    BufferedImage result = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_ARGB);
    Graphics g = result.getGraphics();
    g.drawImage(img, 0, 0, null);

    WritableRaster alphaRaster = result.getAlphaRaster();
    int alpha0[] = new int[] { 0 };
    int alpha255[] = new int[] { 255 };
    for (int y = 0; y < img.getHeight(); y++) {
        for (int x = 0; x < img.getWidth(); x++) {
            alphaRaster.setPixel(x, y, mask.getPixel(x, y) == 0 ? alpha0 : alpha255);
        }
    }

    return result;
}

From source file:com.silverpeas.util.ImageUtil.java

public static String[] getWidthAndHeight(InputStream image) {
    String[] result = new String[2];
    try {/*from  w  w  w . j  av a  2 s. co m*/
        BufferedImage inputBuf = ImageIO.read(image);
        // calcul de la taille de la sortie
        double inputBufWidth = inputBuf.getWidth();
        double inputBufHeight = inputBuf.getHeight();
        String sWidth = Double.toString(inputBufWidth);
        String sHeight = Double.toString(inputBufHeight);

        result[0] = sWidth.substring(0, sWidth.indexOf('.'));
        result[1] = sHeight.substring(0, sHeight.indexOf('.'));

        return result;
    } catch (Exception e) {
        if (image != null) {
            SilverTrace.error("util", "ImageUtil.getWidthAndHeightByHeight", "root.MSG_GEN_ERROR", e);
        }
    }
    result[0] = "";
    result[1] = "";
    return result;
}

From source file:com.reydentx.core.common.PhotoUtils.java

public static boolean isBlackJPEG(BufferedImage bi) {
    if (bi != null) {
        int height = bi.getHeight();
        int width = bi.getWidth();

        for (int x = 0; x < width; x++) {
            for (int y = 0; y < height; y++) {
                if (bi.getRGB(x, y) != -16777216) {
                    return false;
                }//from  www. j  av a2s . c  om
            }
        }
    }

    return true;
}

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

/**
 * check if image size isn't bigger then bigest allowed.
 *
 * @param stream temp file input stream.
 * @param conf connector configuration.// ww w  .j a v a  2s  . com
 * @return true if image size isn't bigger then bigest allowe.
 * @throws IOException when error occurs during reading image.
 */
public static boolean checkImageSize(final InputStream stream, final IConfiguration conf) throws IOException {
    BufferedImage bi = ImageIO.read(stream);
    stream.close();
    if (bi == null) {
        return false;
    }
    if (bi.getHeight() > conf.getImgHeight() || bi.getWidth() > conf.getImgWidth()) {
        return false;
    }

    return true;
}

From source file:de.bund.bfr.knime.pmm.common.chart.ChartUtilities.java

public static PNGImageContent convertToPNGImageContent(JFreeChart chart, int width, int height) {
    try {//from   w ww . j av a2  s.c  o  m
        BufferedImage img;

        if (chart != null) {
            ChartRenderingInfo info = new ChartRenderingInfo();

            img = chart.createBufferedImage(width, 5000, info);
            img = chart.createBufferedImage(width,
                    (int) (img.getHeight() - info.getPlotInfo().getDataArea().getHeight() + height));
        } else {
            img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        }

        return new PNGImageContent(org.jfree.chart.ChartUtilities.encodeAsPNG(img));
    } catch (IOException e) {
        e.printStackTrace();
    }

    return null;
}

From source file:ConvertUtil.java

/**
 * Converts the source to 1-bit colour depth (monochrome). No transparency.
 * /*  w w w  .j  a v  a2  s.  c  o  m*/
 * @param src
 *            the source image to convert
 * @return a copy of the source image with a 1-bit colour depth.
 */
public static BufferedImage convert1(BufferedImage src) {
    IndexColorModel icm = new IndexColorModel(1, 2, new byte[] { (byte) 0, (byte) 0xFF },
            new byte[] { (byte) 0, (byte) 0xFF }, new byte[] { (byte) 0, (byte) 0xFF });

    BufferedImage dest = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_BYTE_BINARY,
            icm);

    ColorConvertOp cco = new ColorConvertOp(src.getColorModel().getColorSpace(),
            dest.getColorModel().getColorSpace(), null);

    cco.filter(src, dest);

    return dest;
}

From source file:ImageUtil.java

public static BufferedImage scale(BufferedImage src, int width, int height) throws IOException {
    BufferedImage dest = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = dest.createGraphics();
    AffineTransform at = AffineTransform.getScaleInstance((double) width / src.getWidth(),
            (double) height / src.getHeight());
    g.drawRenderedImage(src, at);/*www.ja  v  a  2  s .c  o  m*/
    return dest;
}

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

/**
 * check if image size isn't bigger then biggest allowed.
 *
 * @param stream temp file input stream.
 * @param conf connector configuration./*from   w  ww. j  a  va 2s  . c o  m*/
 * @return true if image size isn't bigger then biggest allowed.
 * @throws IOException when error occurs during reading image.
 */
public static boolean checkImageSize(final InputStream stream, final IConfiguration conf) throws IOException {
    final Integer maxWidth = conf.getImgWidth();
    final Integer maxHeight = conf.getImgHeight();
    if (maxHeight == 0 && maxWidth == 0) {
        return true;
    }
    BufferedImage bi = ImageIO.read(stream);
    stream.close();
    if (bi == null) {
        return false;
    }
    return (bi.getHeight() <= maxHeight && bi.getWidth() <= maxWidth);
}

From source file:com.esofthead.mycollab.mobile.ui.MobileAttachmentUtils.java

public static void saveContentsToRepo(String attachmentPath, Map<String, File> fileStores) {
    if (MapUtils.isNotEmpty(fileStores)) {
        ResourceService resourceService = ApplicationContextUtil.getSpringBean(ResourceService.class);
        for (String fileName : fileStores.keySet()) {
            try {
                String fileExt = "";
                int index = fileName.lastIndexOf(".");
                if (index > 0) {
                    fileExt = fileName.substring(index + 1, fileName.length());
                }//from   www.  j ava 2 s.c  o  m

                if ("jpg".equalsIgnoreCase(fileExt) || "png".equalsIgnoreCase(fileExt)) {
                    try {
                        BufferedImage bufferedImage = ImageIO.read(fileStores.get(fileName));

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

                        BufferedImage scaledImage = null;

                        float scale;
                        float destWidth = 974;
                        float destHeight = 718;

                        float scaleX = Math.min(destHeight / imgHeight, 1);
                        float scaleY = Math.min(destWidth / imgWidth, 1);
                        scale = Math.min(scaleX, scaleY);
                        scaledImage = ImageUtil.scaleImage(bufferedImage, scale);

                        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
                        ImageIO.write(scaledImage, fileExt, outStream);

                        resourceService.saveContent(constructContent(fileName, attachmentPath),
                                AppContext.getUsername(), new ByteArrayInputStream(outStream.toByteArray()),
                                AppContext.getAccountId());
                    } catch (IOException e) {
                        LOG.error("Error in upload file", e);
                        resourceService.saveContent(constructContent(fileName, attachmentPath),
                                AppContext.getUsername(), new FileInputStream(fileStores.get(fileName)),
                                AppContext.getAccountId());
                    }
                } else {
                    resourceService.saveContent(constructContent(fileName, attachmentPath),
                            AppContext.getUsername(), new FileInputStream(fileStores.get(fileName)),
                            AppContext.getAccountId());
                }

            } catch (FileNotFoundException e) {
                LOG.error("Error when attach content in UI", e);
            }
        }
    }
}

From source file:ImageProcessing.ImageProcessing.java

public static double[] extractRedColor(BufferedImage source) {
    //Extracts the Red value from the RGB value of the source pixels.
    int imageWidth = source.getWidth();
    int imageHeight = source.getHeight();
    double[] values = new double[imageWidth * imageHeight];

    for (int i = 0; i < imageHeight; i++) {
        for (int j = 0; j < imageWidth; j++) {
            int rgbValue = source.getRGB(j, i);
            Color currentPixel = new Color(rgbValue, true);
            int value = currentPixel.getRed();
            values[(i * imageWidth) + j] = value;
        }//from ww w .j av a  2s.c  o  m
    }

    return values;
}