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:app.model.game.CoverUploadModel.java

public void uploadImage(HttpServletRequest req, Game g)
        throws FileUploadBase.SizeLimitExceededException, FileUploadException, SQLException, Exception {
    int width = 500;
    int height = 800;

    //Bild upload
    FileUpload upload = new FileUpload(2000 * 1024, 5000 * 1024,
            "C:/Users/Public/Arcade/Games/" + g.getGameID() + "/assets",
            "C:/Users/Public/Arcade/Games/" + g.getGameID() + "/tmp/");
    File fileStatus;//  www. j av a2  s.co  m

    fileStatus = upload.uploadFile(req);
    File file = new File(fileStatus.getAbsolutePath());

    BufferedImage img = ImageIO.read(file);
    if (img.getWidth() != width || img.getHeight() != height) {
        img = Scalr.resize(img, Scalr.Method.SPEED, Scalr.Mode.FIT_EXACT, 500, 800);
    }
    File destFile = new File(fileStatus.getParent() + "/" + g.getGameID() + ".jpg");
    ImageIO.write(img, "jpg", destFile);
    g.updateState("coverupload", "complete");
    String state = g.stateToJSON();

    try (SQLHelper sql = new SQLHelper()) {
        sql.execNonQuery("UPDATE `games` SET editState='" + state + "' WHERE ID = " + g.getGameID());
    }

    fileStatus.delete();
}

From source file:com.funambol.foundation.util.MediaUtils.java

/**
 * Rotates given buffered image by given amount of degree.
 * The valid degree values are 0, 90, 180, 270.
 * If the image is a jpg, the rotation is lossless, exif data are preserved
 * and image size is almost the same./*from   ww  w.j a  v  a2 s .  c  om*/
 *
 * @param bufImage the buffered image
 * @param degree amount of degree to apply
 * @return a buffered image containing rotated image data
 * @throws PicturesException if amount of degree is invalid or if an
 *         IOException occurs
 */
private static BufferedImage rotateImage(BufferedImage bufImage, int degree)
        throws FileDataObjecyUtilsException {

    degree = degree % 360;
    int h;
    int w;

    switch (degree) {
    case 0:
    case 180:
        h = bufImage.getHeight();
        w = bufImage.getWidth();
        break;
    case 90:
    case 270:
        h = bufImage.getWidth();
        w = bufImage.getHeight();
        break;
    default:
        throw new FileDataObjecyUtilsException(
                "Error rotating image since the '" + degree + "' degree value is unsupported");
    }

    BufferedImage out = null;

    int bufImageType = bufImage.getType();
    if (BufferedImage.TYPE_BYTE_INDEXED == bufImageType || BufferedImage.TYPE_BYTE_BINARY == bufImageType) {

        IndexColorModel model = (IndexColorModel) bufImage.getColorModel();
        out = new BufferedImage(w, h, bufImage.getType(), model);

    } else if (BufferedImage.TYPE_CUSTOM == bufImageType) {

        // we don't know what type of image it can be

        // there's a bug in some VM that cause some PNG images to have 
        // type custom: this should take care of this issue

        //check if we need to have alpha channel
        boolean alpha = bufImage.getTransparency() != BufferedImage.OPAQUE;

        if (alpha) {
            // TYPE_INT_ARGB_PRE gives you smaller output images
            // than TYPE_INT_ARGB
            out = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB_PRE);
        } else {
            out = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
        }

    } else {

        out = new BufferedImage(w, h, bufImage.getType());
    }

    Graphics2D g2d = out.createGraphics();

    Map renderingHints = new HashMap();

    renderingHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    renderingHints.put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);

    g2d.setRenderingHints(renderingHints);
    g2d.rotate(Math.toRadians(degree));

    switch (degree) {
    case 90:
        g2d.translate(0, -w);
        break;
    case 180:
        g2d.translate(-w, -h);
        break;
    case 270:
        g2d.translate(-h, 0);
        break;
    }

    g2d.drawImage(bufImage, null, 0, 0);
    g2d.dispose();

    return out;
}

From source file:com.trailmagic.image.util.FixDimensions.java

public void fixDimensions(final String ownerName, final String rollName) {
    m_hibernateTemplate.execute(new HibernateCallback() {
        public Object doInHibernate(Session session) {
            try {
                User owner = userRepository.getByScreenName(ownerName);
                ImageGroup roll = imageGroupRepository.getRollByOwnerAndName(owner, rollName);

                for (ImageFrame frame : roll.getFrames()) {
                    Image image = frame.getImage();
                    for (ImageManifestation mf : image.getManifestations()) {
                        HeavyImageManifestation heavyMf = m_imageManifestationFactory.getHeavyById(mf.getId());
                        BufferedImage bi = ImageIO.read(heavyMf.getData().getBinaryStream());
                        mf.setHeight(bi.getHeight());
                        mf.setWidth(bi.getWidth());
                        session.evict(heavyMf);
                    }// www. j  a  v  a 2s .  c  o  m
                }
            } catch (Exception e) {
                s_log.error("Error fixing permissions", e);
            }
            return null;
        }
    });
}

From source file:GraphicsUtil.java

public void drawCentered(BufferedImage img, Point2D location) {
    drawCentered(g, img, location, img.getWidth(), img.getHeight(), observer);
}

From source file:eu.novait.imageresizer.helpers.ImageConverter.java

public void process() throws IOException {
    BufferedImage inImage = ImageIO.read(this.file);
    double ratio = (double) inImage.getWidth() / (double) inImage.getHeight();
    int w = this.width;
    int h = this.height;
    if (inImage.getWidth() >= inImage.getHeight()) {
        w = this.width;
        h = (int) Math.round(w / ratio);
    } else {//from w ww .  j a v  a 2  s .  c  o m
        h = this.height;
        w = (int) Math.round(ratio * h);
    }
    int type = inImage.getType() == 0 ? BufferedImage.TYPE_INT_ARGB : inImage.getType();
    BufferedImage outImage = new BufferedImage(w, h, type);
    Graphics2D g = outImage.createGraphics();
    g.drawImage(inImage, 0, 0, w, h, null);
    g.dispose();
    String ext = FilenameUtils.getExtension(this.file.getAbsolutePath());
    String t = "jpg";
    switch (ext) {
    case "png":
        t = "png";
        break;
    }
    ImageIO.write(outImage, t, this.outputfile);
}

From source file:ch.admin.isb.hermes5.util.ImageUtilsTest.java

@Test
public void testScaleByHeight() {
    byte[] gifStream = getResourceAsStream("logo.jpg");
    BufferedImage bufferedImage = imageUtil.toBufferedImage(gifStream);
    BufferedImage makeSmallerToMax = imageUtil.makeSmallerToMax(bufferedImage, 200, 50);
    assertEquals(50, makeSmallerToMax.getHeight());
    assertEquals((int) (50.0 * bufferedImage.getWidth() / bufferedImage.getHeight()) + 1 /*RUNDUNGSFEHLER*/,
            makeSmallerToMax.getWidth());
}

From source file:edu.ku.brc.util.thumbnails.ImageThumbnailGenerator.java

/**
 * Creates a thumbnail of the given image bytes.
 * /*from  ww  w. ja va 2 s . com*/
 * @param originalImageData the bytes of the input file
 * @param doHighQuality higher quality thumbnail (slower)
 * @return the bytes of the output file
 * @throws IOException if any IO errors occur during generation or storing the output
 */
public byte[] generateThumbnail(final byte[] originalImageData, final boolean doHighQuality)
        throws IOException {
    ByteArrayInputStream inputStr = new ByteArrayInputStream(originalImageData);
    if (inputStr != null) {
        BufferedImage orig = ImageIO.read(inputStr);
        if (orig != null) {
            if (orig.getHeight() < maxSize.getHeight() && orig.getWidth() < maxSize.getWidth()) {
                // there's no need to do anything since the original is already under the max size
                return originalImageData;
            }

            byte[] scaledImgData = GraphicsUtils.scaleImage(orig, maxSize.height, maxSize.width, true,
                    doHighQuality);
            return scaledImgData;
        }
    }
    return null;
}

From source file:no.dusken.aranea.service.StoreImageServiceImpl.java

public Image changeImage(File file, Image image) throws IOException {

    String hash = MD5.asHex(MD5.getHash(file));

    if (isBlank(hash)) {
        throw new IOException("Could not get hash from " + file.getAbsolutePath());
    }//from  ww w.j  av a2 s .  c  o  m

    Image existingImage = imageService.getImageByHash(hash);
    if (existingImage != null) {
        log.info("Imported existing Image: {} from the user", existingImage.toString());
        file.delete();
        return existingImage;
    } else {
        image.setHash(hash);

        BufferedImage rendImage = ImageIO.read(file);
        image.setHeight(rendImage.getHeight());
        image.setWidth(rendImage.getWidth());
        image.setFileSize(file.length());
        FileUtils.copyFile(file, new File(imageDirectory + "/" + image.getUrl()));

        file.delete();
        log.debug("Imported Image: {} from {}", image.toString(), file.getAbsolutePath());

        return imageService.saveOrUpdate(image);
    }
}

From source file:Main.java

public void createThumbnail(File file) throws Exception {
    BufferedImage img = ImageIO.read(file);
    BufferedImage thumb = new BufferedImage(100, 200, BufferedImage.TYPE_INT_RGB);

    Graphics2D g2d = (Graphics2D) thumb.getGraphics();
    g2d.drawImage(img, 0, 0, thumb.getWidth() - 1, thumb.getHeight() - 1, 0, 0, img.getWidth() - 1,
            img.getHeight() - 1, null);/*from   w w w. j a  v a  2  s .  com*/
    g2d.dispose();
    ImageIO.write(thumb, "PNG", new File("thumb.png"));
}

From source file:fi.helsinki.opintoni.service.ImageService.java

private BufferedImage toJpg(BufferedImage bufferedImage) {
    BufferedImage jpgImage = new BufferedImage(bufferedImage.getWidth(), bufferedImage.getHeight(),
            BufferedImage.TYPE_INT_RGB);
    jpgImage.createGraphics().drawImage(bufferedImage, 0, 0, Color.BLACK, null);
    return jpgImage;
}