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:io.gameover.utilities.pixeleditor.Frame.java

public BufferedImage getAsBufferedImage(Color transparent) {
    BufferedImage bi = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
    for (int i = 0; i < bi.getWidth(); i++) {
        for (int j = 0; j < bi.getHeight(); j++) {
            if (transparent != null && argb[i][j] == NO_COLOR_AS_INT) {
                bi.setRGB(i, j, transparent.getRGB());
            } else {
                bi.setRGB(i, j, argb[i][j]);
            }// ww w .  ja  v  a 2s . co m
        }
    }
    return bi;
}

From source file:com.mycompany.controllers.ClubController.java

private byte[] LogoConvertion(byte[] bytes) {
    int width = 200;
    int height = 200;
    ByteArrayInputStream in = new ByteArrayInputStream(bytes);
    try {//w  w  w  .  j  a  v  a 2  s. com
        BufferedImage img = ImageIO.read(in);
        if (height == 0) {
            height = (width * img.getHeight()) / img.getWidth();
        }
        if (width == 0) {
            width = (height * img.getWidth()) / img.getHeight();
        }
        Image scaledImage = img.getScaledInstance(width, height, Image.SCALE_SMOOTH);
        BufferedImage imageBuff = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        imageBuff.getGraphics().drawImage(scaledImage, 0, 0, new Color(0, 0, 0), null);

        ByteArrayOutputStream buffer = new ByteArrayOutputStream();

        ImageIO.write(imageBuff, "jpg", buffer);

        bytes = buffer.toByteArray();
    } catch (IOException e) {
        log.error("File convertion error");
    }
    return bytes;
}

From source file:edworld.pdfreader4humans.PDFReaderTest.java

private void assertImagesAreSimilar(InputStream expectedOutputStream, BufferedImage outputImage)
        throws IOException {
    try {/*  w  w  w .ja v a 2 s. co m*/
        BufferedImage expectedOutputImage = ImageIO.read(expectedOutputStream);
        assertEquals(expectedOutputImage.getType(), outputImage.getType());
        assertEquals(expectedOutputImage.getWidth(), outputImage.getWidth());
        assertEquals(expectedOutputImage.getHeight(), outputImage.getHeight());
        assertEquals(expectedOutputImage.getTransparency(), outputImage.getTransparency());
        for (int k = 0; k < Math.max(outputImage.getWidth(), outputImage.getHeight()); k++) {
            int kX = k % outputImage.getWidth();
            int kY = k % outputImage.getHeight();
            int expectedColor = expectedOutputImage.getRGB(kX, kY);
            int actualColor = outputImage.getRGB(kX, kY);
            if ((expectedColor ^ 0xFFFFFF) == actualColor)
                expectedColor ^= 0xFFFFFF;
            assertEquals("Color should be the same at (" + k + "," + k + ").", expectedColor, actualColor);
        }
    } finally {
        expectedOutputStream.close();
    }
}

From source file:com.esofthead.mycollab.vaadin.ui.AttachmentPanel.java

public void saveContentsToRepo(String attachmentPath) {
    if (MapUtils.isNotEmpty(fileStores)) {
        for (String fileName : fileStores.keySet()) {
            try {
                String fileExt = "";
                int index = fileName.lastIndexOf(".");
                if (index > 0) {
                    fileExt = fileName.substring(index + 1, fileName.length());
                }/*w ww  . j  av  a2s . co  m*/

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

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

                        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);
                        BufferedImage 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:apiserver.services.images.services.jhlabs.MaskFilterService.java

public Object doFilter(Message<?> message) throws MessageConfigException {
    MaskJob props = (MaskJob) message.getPayload();

    Object maskImage = props.getMask();

    try {/*  w  w w.j ava2  s .c om*/
        BufferedImage bufferedImage = props.getBufferedImage();
        if (bufferedImage == null) {
            throw new MessageConfigException(MessageConfigException.MISSING_PROPERTY);
        }

        BufferedImage destImage = new BufferedImage(bufferedImage.getWidth(), bufferedImage.getHeight(),
                bufferedImage.getType());

        //run filter
        ApplyMaskFilter filter = new ApplyMaskFilter();
        filter.setDestination(destImage);

        filter.setMaskImage(bufferedImage);

        BufferedImage outFile = filter.filter(bufferedImage, null);

        props.setBufferedImage(outFile);
        return message;
    } catch (Throwable e) {
        //log.error(e.getMessage(), e);
        throw new RuntimeException(e);
    }
}

From source file:cpcc.ros.sim.osm.CameraTest.java

@Test(dataProvider = "imageDataProvider")
public void shouldGetImageForGivenPositionAndHeight(PolarCoordinate position, int width, int height,
        String imageFormat, String imageName) throws IOException {
    byte[] buffer = camera.getImage(position);
    BufferedImage image = ImageIO.read(new ByteArrayInputStream(buffer));
    assertThat(image.getHeight()).isEqualTo(height);
    assertThat(image.getWidth()).isEqualTo(width);

    byte[] reference = FileUtils.readFileToByteArray(new File(imageName));
    assertThat(buffer).isEqualTo(reference);
}

From source file:org.jamwiki.servlets.UploadServlet.java

/**
 * @return ImageData object from uploaded binary data.
 *//*from   ww w .j  a va 2 s  .  c om*/
private ImageData processImageData(String contentType, byte buff[]) {
    int width = -1;
    int height = -1;
    try {
        BufferedImage image = ImageIO.read(new ByteArrayInputStream(buff));
        if (image != null) {
            width = image.getWidth();
            height = image.getHeight();
        }
    } catch (IOException e) {
        logger.info("Failure while processing image", e);
    }
    return new ImageData(contentType, width, height, buff);
}

From source file:main.java.whiteSocket.Bloop.java

public static BufferedImage loadSketch() throws Exception {
    /**/*from  w w w  . ja  va2 s.  c  o  m*/
     * load image from DB table - either an input sketch or a compiled blooprint image
     *   sketch arg = "null"
     * BLOB object to binary stream to BufferedImage object
     * */
    System.out.println("loadSketch() from " + sketchFile);
    InputStream stream = null;
    BufferedImage some = null;
    try {
        /**
         * http://stackoverflow.com/questions/39081215/access-a-resource-outside-a-jar-from-the-jar
         * */

        stream = Bloop.class.getClass().getResourceAsStream(sketchFile);
        //         stream = null;

        if (!jarMode) {
            some = ImageIO.read(new File(sketchFile));
            Stretch.fx = some.getWidth() - 1;
            Stretch.gx = some.getWidth() - 1;
            Stretch.fy = some.getHeight() - 1;
            Stretch.hy = some.getHeight() - 1;
            return some;
        }
        System.out.println("sketch stream = " + stream);
    } catch (Exception e) {
        System.out.print("error sketch to stream: ");
        System.out.println(e.getMessage());
    }
    try {
        some = ImageIO.read(stream);
        Stretch.fx = some.getWidth() - 1;
        Stretch.gx = some.getWidth() - 1;
        Stretch.fy = some.getHeight() - 1;
        Stretch.hy = some.getHeight() - 1;
    } catch (Exception exc) {
        System.out.print("error stream to image: ");
        System.out.println(exc.getMessage());
    }
    return some;
}

From source file:cpcc.ros.services.RosImageConverterTest.java

@Test
public void shouldReturnAnEmptyImageForUnknownImageFormats() {
    int height = 91;
    int width = 121;
    String encoding = "unknownImageFormat";

    when(message.getEncoding()).thenReturn(encoding);
    when(message.getHeight()).thenReturn(height);
    when(message.getWidth()).thenReturn(width);

    BufferedImage result = conv.messageToBufferedImage(message);
    assertThat(result).isNotNull();/*from ww w  .  j  a  v  a  2  s  .  c  o m*/

    assertThat(result.getHeight()).isEqualTo(height);
    assertThat(result.getWidth()).isEqualTo(width);

    assertThatImageIsEmpty(result);
}