Example usage for java.awt Image getHeight

List of usage examples for java.awt Image getHeight

Introduction

In this page you can find the example usage for java.awt Image getHeight.

Prototype

public abstract int getHeight(ImageObserver observer);

Source Link

Document

Determines the height of the image.

Usage

From source file:com.krawler.esp.handlers.genericFileUpload.java

private BufferedImage toBufferedImage(Image image) {
    image = new ImageIcon(image).getImage();
    BufferedImage bufferedImage = new BufferedImage(image.getWidth(null), image.getHeight(null),
            BufferedImage.TYPE_INT_RGB);
    Graphics g = bufferedImage.createGraphics();
    g.setColor(Color.white);//ww  w  . j a  va2s .  c  o  m
    g.fillRect(0, 0, image.getWidth(null), image.getHeight(null));
    g.drawImage(image, 0, 0, null);
    g.dispose();

    return bufferedImage;
}

From source file:com.krawler.esp.handlers.genericFileUpload.java

private BufferedImage toBufferedCompanyImage(Image image) {
    image = new ImageIcon(image).getImage();
    BufferedImage bufferedImage = new BufferedImage(image.getWidth(null), image.getHeight(null),
            BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = bufferedImage.createGraphics();
    //       java.awt.Color transparent = new java.awt.Color(255, 255, 255, 1);
    //                g.setColor(transparent);
    //                int rule = java.awt.AlphaComposite.SRC_OVER;
    //                        
    //                java.awt.AlphaComposite ac = java.awt.AlphaComposite.getInstance(rule,1);
    //                g.setComposite(ac);
    //      g.fillRect(0, 0, image.getWidth(null), image.getHeight(null));
    g.drawImage(image, 0, 0, null);// ww w  .j  ava 2s  .  co m
    g.dispose();

    return bufferedImage;
}

From source file:de.romankreisel.faktotum.beans.BundesbruderBean.java

private Byte[] storeImageToByteArray(Image image) throws IOException {
    if (!(image instanceof RenderedImage)) {
        BufferedImage newImage = new BufferedImage(image.getWidth(null), image.getHeight(null),
                BufferedImage.TYPE_INT_RGB);
        newImage.getGraphics().drawImage(image, 0, 0, null);
        image = newImage;//w  w w  .  j  av a  2 s  .c  o  m
    }
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    ImageIO.write((RenderedImage) image, "jpg", byteArrayOutputStream);
    byteArrayOutputStream.flush();
    byte[] imageInByte = byteArrayOutputStream.toByteArray();
    byteArrayOutputStream.close();
    return ArrayUtils.toObject(imageInByte);
}

From source file:org.colombbus.tangara.AboutWindow.java

public AboutWindow(JFrame frame, Image baseHeaderImage) {
    super(frame, true);
    windowWidth = baseHeaderImage.getWidth(null);
    windowHeight = baseHeaderImage.getHeight(null);
    setLocationAndSize();//from w  w  w .j  a  v a  2s.  c  o  m
    initialize(baseHeaderImage);
}

From source file:org.colombbus.tangara.AboutWindow.java

private BufferedImage createBackgroundImage(Image baseBackgroundImg) {
    BufferedImage newImg = new BufferedImage(baseBackgroundImg.getWidth(null),
            baseBackgroundImg.getHeight(null), BufferedImage.TYPE_INT_RGB);
    newImg.getGraphics().drawImage(baseBackgroundImg, 0, 0, null);
    Graphics2D drawingGraphics = (Graphics2D) newImg.getGraphics();
    Color titleColor = Configuration.instance().getColor("tangara.title.color");
    String titleText = Configuration.instance().getString("tangara.title");
    Font titleFont = Configuration.instance().getFont("tangara.title.font");
    drawingGraphics.setFont(titleFont);//from  w  w  w  . ja  va 2 s .  c o  m
    drawingGraphics.setColor(titleColor);
    drawingGraphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
            RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    drawingGraphics.drawString(titleText, marginLeft, windowHeight / 2 - marginText);
    return newImg;
}

From source file:org.jtalks.jcommune.service.nontransactional.ImageConverterTest.java

@Test(dataProvider = "parameterResizeImage")
public void testResizeImage(int maxWidth, int maxHeight, int imageType, String format) throws IOException {
    int expectedWidth = 4;
    int expectedHeight = 4;
    imageConverter = new ImageConverter(format, imageType, maxWidth, maxHeight);
    BufferedImage originalImage = ImageIO
            .read(new MockMultipartFile("test_image", "test_image", "image/png", originalImageByteArray)
                    .getInputStream());/*from ww w  .ja  va 2 s.  c  om*/
    Image modifiedImage = imageConverter.resizeImage(originalImage, imageType);
    assertEquals(modifiedImage.getWidth(null), expectedWidth);
    assertEquals(modifiedImage.getHeight(null), expectedHeight);
}

From source file:org.polymap.core.data.image.ImageGrayscaleProcessor.java

protected Image grayscale(Image image) {
    long start = System.currentTimeMillis();

    // load image data
    new javax.swing.ImageIcon(image).getImage();

    if (!(image instanceof BufferedImage)) {
        BufferedImage bimage = new BufferedImage(image.getHeight(null), image.getWidth(null),
                BufferedImage.TYPE_4BYTE_ABGR);
        Graphics g = bimage.getGraphics();
        g.drawImage(image, 0, 0, null);/*  w  ww .j  av  a 2s  . co  m*/
        g.dispose();

        image = bimage;
    }

    // grayscale
    ColorConvertOp filter = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null);

    BufferedImage grayImage = new BufferedImage(image.getHeight(null), image.getWidth(null),
            BufferedImage.TYPE_4BYTE_ABGR);

    Graphics g = grayImage.getGraphics();
    filter.filter((BufferedImage) image, grayImage);
    g.dispose();

    log.info("Gray scaling took: " + (System.currentTimeMillis() - start) + "ms");
    return grayImage;
}

From source file:com.t3.image.ThumbnailManager.java

private Image createThumbnail(File file) throws IOException {

    // Gather info
    File thumbnailFile = getThumbnailFile(file);
    if (thumbnailFile.exists()) {
        return ImageUtil.getImage(thumbnailFile);
    }/*from  w w w .  ja v  a 2  s.c  o m*/

    Image image = ImageUtil.getImage(file);

    // Should we bother making a thumbnail ?
    if (file.length() < 30 * 1024) {
        return image;
    }

    // Transform the image
    Dimension imgSize = new Dimension(image.getWidth(null), image.getHeight(null));
    SwingUtil.constrainTo(imgSize, thumbnailSize.width, thumbnailSize.height);

    BufferedImage thumbnailImage = new BufferedImage(imgSize.width, imgSize.height,
            ImageUtil.pickBestTransparency(image));

    Graphics2D g = thumbnailImage.createGraphics();
    g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    g.drawImage(image, 0, 0, imgSize.width, imgSize.height, null);
    g.dispose();

    // Ensure path exists
    if (thumbnailFile.exists())
        thumbnailFile.delete();
    else
        thumbnailFile.getParentFile().mkdirs();

    try (OutputStream os = new FileOutputStream(thumbnailFile)) {
        IOUtils.write(ImageUtil.imageToBytes(thumbnailImage, "png"), os);
    }

    return thumbnailImage;
}

From source file:com.krawler.esp.handlers.genericFileUpload.java

public final void imgResizeCompany(String imagePath, int Width, int Height, String fName, boolean ori)
        throws IOException {
    try {//from w  w  w .  j a  va2s  .c om
        // Get a path to the image to resize.
        // ImageIcon is a kluge to make sure the image is fully
        // loaded before we proceed.
        Image sourceImage = new ImageIcon(Toolkit.getDefaultToolkit().getImage(imagePath)).getImage();
        int imageWidth = sourceImage.getWidth(null);
        int imageHeight = sourceImage.getHeight(null);
        if (ori) {
            Width = imageWidth;
            Height = imageHeight;
        } else {
            Width = imageWidth < Width ? imageWidth : Width;
            Height = imageHeight < Height ? imageHeight : Height;
            float imageRatio = ((float) imageWidth / (float) imageHeight);
            float framemageratio = ((float) Width / (float) Height);
            if (imageRatio > framemageratio) {
                float value = Width / imageRatio;
                Height = (int) value;

            } else {
                float value = Height * imageRatio;
                Width = (int) value;
            }
        }
        BufferedImage resizedImage = this.scaleCompanyImage(sourceImage, Width, Height);
        ImageIO.write(resizedImage, "PNG", new File(fName + ".png"));
        sourceImage.flush();
    } catch (Exception e) {
        this.ErrorMsg = "Problem occured while uploading logo";
        logger.warn(e.getMessage(), e);
    }
}

From source file:ddf.catalog.transformer.input.tika.TikaInputTransformer.java

private void createThumbnail(InputStream input, Metacard metacard) {
    try {/*from   w w w  .  j ava2 s.  c om*/
        Image image = ImageIO.read(new CloseShieldInputStream(input));

        if (null != image) {
            BufferedImage bufferedImage = new BufferedImage(image.getWidth(null), image.getHeight(null),
                    BufferedImage.TYPE_INT_RGB);
            Graphics2D graphics = bufferedImage.createGraphics();
            graphics.drawImage(image, null, null);
            graphics.dispose();

            BufferedImage thumb = Scalr.resize(bufferedImage, 200);

            try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
                ImageIO.write(thumb, "jpeg", out);

                byte[] thumbBytes = out.toByteArray();
                metacard.setAttribute(new AttributeImpl(Metacard.THUMBNAIL, thumbBytes));
            }
        } else {
            LOGGER.warn("Unable to read image from input stream to create thumbnail.");
        }
    } catch (Exception e) {
        LOGGER.warn("Unable to read image from input stream to create thumbnail.", e);
    }
}