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:info.magnolia.filesystembrowser.app.imageprovider.FSImageProvider.java

private Resource scaleImage(File file) {
    FileInputStream fis = null;//  w w w .  jav a 2 s. c  om
    try {
        fis = new FileInputStream(file);
        final BufferedImage img = ImageIO.read(fis);
        if (img != null) {
            int width = img.getWidth();
            int height = img.getHeight();
            BufferedImage result = img;
            if (width > 200) {
                double ratio = (double) height / width;
                int newWidth = 200;
                int newHeight = (int) (newWidth * ratio);
                result = new ScaleFilter(newWidth, newHeight).filter(img, null);
                result = new CropFilter(0, 0, newWidth, newHeight).filter(result, null);
            }
            final InputStream is = createStreamSource(result, "png");
            StreamResource.StreamSource streamSource = new StreamResource.StreamSource() {

                @Override
                public InputStream getStream() {
                    return is;
                }
            };
            return new StreamResource(streamSource, "image" + System.currentTimeMillis() + ".png");
        }
    } catch (IOException e) {
        log.error("Failed to scale a resource {}.", file, e);
    } finally {
        IOUtils.closeQuietly(fis);
    }
    return null;
}

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

private BufferedImage getCachedThumbnail(File file) {

    File thumbnailFile = getThumbnailFile(file);

    if (!thumbnailFile.exists()) {
        return null;
    }//from   w w  w  .j a  va 2  s.c om

    try {
        // Check that it hasn't changed on disk
        if (file.lastModified() > thumbnailFile.lastModified()) {
            return null;
        }

        // Get the thumbnail
        BufferedImage thumbnail = ImageIO.read(thumbnailFile);

        // Check that we have the size we want
        if (thumbnail.getWidth() != thumbnailSize.width && thumbnail.getHeight() != thumbnailSize.height) {
            return null;
        }

        return thumbnail;
    } catch (IOException ioe) {
        return null;
    }
}

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

public static BufferedImage scaleImage(BufferedImage image, int width, int height) {
    assert (width > 0 && height > 0);
    // create image of new size
    BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics g = img.getGraphics();
    ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_INTERPOLATION,
            RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
    //  ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    g.drawImage(image, 0, 0, img.getWidth(), img.getHeight(), null);
    return img;/*from  w  w w.  j  a  v  a 2 s  .  c o  m*/
}

From source file:maltcms.ui.fileHandles.serialized.SeriesPaintComboBoxRenderer.java

private BufferedImage createColorImage(Paint p) {
    BufferedImage bi = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = bi.createGraphics();
    g2.setPaint(p);/*w ww  . j a  va  2  s .  c om*/
    g2.fillRect(0, 0, bi.getWidth(), bi.getHeight());
    return bi;
}

From source file:contactangle.ImageControl.java

public void setImage(BufferedImage img) {
    this.img = applyEdgeDetect(img);

    if (img != null)
        setPreferredSize(new Dimension(img.getWidth(), img.getHeight()));
    else//from w w w  . j  a v  a  2 s  . com
        setPreferredSize(new Dimension(200, 50));
}

From source file:doge.photo.DogePhotoManipulator.java

private void renderBackground(BufferedImage sourceImage, BufferedImage destinationImage,
        Graphics2D destinationGraphics) {
    destinationGraphics.drawImage(sourceImage, 0, 0, IMAGE_WIDTH, destinationImage.getHeight(), null);
}

From source file:org.shredzone.cilla.admin.AbstractImageBean.java

/**
 * Scales a {@link BufferedImage} to the given size, keeping the aspect ratio. If the
 * image is smaller than the resulting size, it will be magnified.
 *
 * @param image/*  ww  w .  j a va2 s  .  co  m*/
 *            {@link BufferedImage} to scale
 * @param width
 *            Maximum result width
 * @param height
 *            Maximum result height
 * @return {@link BufferedImage} with the scaled image
 */
private BufferedImage scale(BufferedImage image, int width, int height) {
    ImageObserver observer = null;

    Image scaled = null;
    if (image.getWidth() > image.getHeight()) {
        scaled = image.getScaledInstance(width, -1, Image.SCALE_SMOOTH);
    } else {
        scaled = image.getScaledInstance(-1, height, Image.SCALE_SMOOTH);
    }

    BufferedImage result = new BufferedImage(scaled.getWidth(observer), scaled.getHeight(observer),
            BufferedImage.TYPE_INT_RGB);
    result.createGraphics().drawImage(scaled, 0, 0, observer);
    return result;
}

From source file:SplashScreen.java

public SplashScreen(final BufferedImage img) {
    JPanel panel = new JPanel() {
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2d = (Graphics2D) g.create();

            g2d.drawImage(img, 0, 0, img.getWidth(), img.getHeight(), SplashScreen.this);
        }/*from  w  w w .ja v a2s .  c o m*/
    };
    panel.setPreferredSize(new Dimension(img.getWidth(), img.getHeight()));

    Container content = getContentPane();
    content.setLayout(new BorderLayout());
    content.add(panel, BorderLayout.NORTH);
    content.add(label = new JLabel(), BorderLayout.CENTER);
    content.add(bar = new JProgressBar(), BorderLayout.SOUTH);
    pack();
    setLocationRelativeTo(null);
}

From source file:ddf.catalog.transformer.OverlayMetacardTransformerTest.java

@Test
public void testOverlaySquishedHeight() throws Exception {
    final MetacardImpl metacard = getMetacard();
    metacard.setLocation("POLYGON ((0 0, 1 0, 1 -0.1, 0 -0.1, 0 0))");
    final BinaryContent content = transform(metacard, null);

    final BufferedImage originalImage = getImage(getImageBytes());
    final BufferedImage overlayImage = getImage(content.getByteArray());

    assertThat(overlayImage.getWidth(), equalTo(originalImage.getWidth()));
    assertThat(overlayImage.getHeight(), lessThan(originalImage.getHeight()));
}

From source file:ddf.catalog.transformer.input.pdf.PdfInputTransformer.java

private byte[] generatePdfThumbnail(PDDocument pdfDocument) throws IOException {

    PDFRenderer pdfRenderer = new PDFRenderer(pdfDocument);

    if (pdfDocument.getNumberOfPages() < 1) {
        /*//  w ww  . ja  va  2  s  .  c om
         * Can there be a PDF with zero pages??? Should we throw an error or what? The
         * original implementation assumed that a PDF would always have at least one
         * page. That's what I've implemented here, but I don't like make those
         * kinds of assumptions :-( But I also don't want to change the original
         * behavior without knowing how it will impact the system.
         */
    }

    PDPage page = pdfDocument.getPage(0);

    BufferedImage image = pdfRenderer.renderImageWithDPI(0, RESOLUTION_DPI, ImageType.RGB);

    int largestDimension = Math.max(image.getHeight(), image.getWidth());
    float scalingFactor = IMAGE_HEIGHTWIDTH / largestDimension;
    int scaledHeight = (int) (image.getHeight() * scalingFactor);
    int scaledWidth = (int) (image.getWidth() * scalingFactor);

    BufferedImage scaledImage = new BufferedImage(scaledWidth, scaledHeight, BufferedImage.TYPE_INT_RGB);
    Graphics2D graphics = scaledImage.createGraphics();
    graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    graphics.drawImage(image, 0, 0, scaledWidth, scaledHeight, null);
    graphics.dispose();

    try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
        ImageIOUtil.writeImage(scaledImage, FORMAT_NAME, outputStream, RESOLUTION_DPI, IMAGE_QUALITY);
        return outputStream.toByteArray();
    }
}