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:org.iish.visualmets.services.ImageTransformation.java

/**
 * Returns a 270 degrees rotated image/* w  w  w. j a v  a 2  s  . c o m*/
 *
 * @param bi image
 * @return a rotated image
 */
private BufferedImage RotateImage270Degrees(BufferedImage bi) {
    int width = bi.getWidth();
    int height = bi.getHeight();

    BufferedImage biFlip = new BufferedImage(height, width, bi.getType());

    for (int i = 0; i < width; i++)
        for (int j = 0; j < height; j++) {
            biFlip.setRGB(j, width - 1 - i, bi.getRGB(i, j));
        }

    return biFlip;
}

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

public void rotateProfilePictureClockwise(BundesbruderEntity bundesbruder, double angle) throws IOException {
    BufferedImage image = this.getImageFromByteArray(bundesbruder.getPictureOriginal());
    double sin = Math.abs(Math.sin(angle)), cos = Math.abs(Math.cos(angle));
    int w = image.getWidth(), h = image.getHeight();
    int neww = (int) Math.floor(w * cos + h * sin), newh = (int) Math.floor(h * cos + w * sin);
    GraphicsConfiguration gc = image.createGraphics().getDeviceConfiguration();
    BufferedImage result = gc.createCompatibleImage(neww, newh, Transparency.TRANSLUCENT);
    Graphics2D g = result.createGraphics();
    g.translate((neww - w) / 2, (newh - h) / 2);
    g.rotate(angle, w / 2, h / 2);//  w  ww. j a v a2  s .  c om
    g.drawRenderedImage(image, null);
    g.dispose();
    this.setProfilePicture(bundesbruder, this.storeImageToByteArray(image));
}

From source file:haven.Utils.java

static Coord imgsz(BufferedImage img) {
    return (new Coord(img.getWidth(), img.getHeight()));
}

From source file:com.tascape.qa.th.android.driver.AdbDevice.java

private boolean bufferedImagesEqual(BufferedImage img1, BufferedImage img2) {
    if (img1.getWidth() != img2.getWidth() || img1.getHeight() != img2.getHeight()) {
        return false;
    }//from   www. j ava  2s.c  o m

    boolean equal = true;
    for (int x = 100; x < img1.getWidth() - 100; x++) {
        for (int y = 100; y < img1.getHeight() - 100; y++) {
            if (img1.getRGB(x, y) != img2.getRGB(x, y)) {
                equal = false;
            }
        }
    }
    return equal;
}

From source file:architecture.ee.web.attachment.DefaultAttachmentManager.java

protected File getThumbnailFromCacheIfExist(Attachment attach, int width, int height) throws IOException {

    log.debug("thumbnail generation " + width + "x" + height);
    File dir = getAttachmentCacheDir();
    File file = new File(dir, toThumbnailFilename(attach, width, height));
    File originalFile = getAttachmentFromCacheIfExist(attach);
    log.debug("source: " + originalFile.getAbsoluteFile() + ", " + originalFile.length());
    log.debug("thumbnail:" + file.getAbsoluteFile());

    if (file.exists() && file.length() > 0) {
        attach.setThumbnailSize((int) file.length());
        return file;
    }//www  .j ava  2s.  co m

    if (StringUtils.endsWithIgnoreCase(attach.getContentType(), "pdf")) {
        PDDocument document = PDDocument.load(originalFile);
        List<PDPage> pages = document.getDocumentCatalog().getAllPages();
        PDPage page = pages.get(0);
        BufferedImage image = page.convertToImage(BufferedImage.TYPE_INT_RGB, 72);
        ImageIO.write(Thumbnails.of(image).size(width, height).asBufferedImage(), "png", file);
        attach.setThumbnailSize((int) file.length());
        return file;
    } else if (StringUtils.startsWithIgnoreCase(attach.getContentType(), "image")) {
        BufferedImage originalImage = ImageIO.read(originalFile);
        if (originalImage.getHeight() < height || originalImage.getWidth() < width) {
            attach.setThumbnailSize(0);
            return originalFile;
        }
        BufferedImage thumbnail = Thumbnails.of(originalImage).size(width, height).asBufferedImage();
        ImageIO.write(thumbnail, "png", file);
        attach.setThumbnailSize((int) file.length());
        return file;
    }

    return null;
}

From source file:net.malisis.advert.advert.Advert.java

protected void loadFile() {
    if (file == null || !file.exists())
        return;//from  w  w  w.j  a v a 2s . co m

    size = file.length();
    BufferedImage img;
    try {
        img = ImageIO.read(new ByteArrayInputStream(Files.toByteArray(file)));
        if (img != null) {
            width = img.getWidth();
            height = img.getHeight();
        }
    } catch (IOException e) {
        MalisisAdvert.log.error("Could not get image infos for {}", this, e);
    }
}

From source file:it.smartcommunitylab.parking.management.web.manager.MarkerIconStorage.java

private void generateMarkerWithFlag(String basePath, String company, String entity, String color)
        throws IOException {
    BufferedImage templateIcon = ImageIO.read(new File(getIconFolder(basePath, ICON_FOLDER) + TEMPLATE_FILE));
    BufferedImage icon = new BufferedImage(templateIcon.getWidth(), templateIcon.getHeight() + ICON_INCR_HEIGHT,
            BufferedImage.TYPE_INT_ARGB);
    Graphics2D graphics = icon.createGraphics();
    graphics.setColor(new Color(Integer.parseInt(color, 16)));
    graphics.drawRect(0, 0, icon.getWidth(), COLOR_RECT_HEIGHT);
    graphics.fillRect(0, 0, icon.getWidth(), COLOR_RECT_HEIGHT);
    graphics.drawImage(templateIcon, 0, ICON_INCR_HEIGHT, null);
    graphics.dispose();/* w  w  w.  jav  a  2  s  .c  om*/
    ImageIO.write(icon, ICON_TYPE, new File(getIconFolder(basePath, ICON_FOLDER_CACHE) + company + "-" + entity
            + "-" + color + ICON_EXTENSION));
}

From source file:org.kawakicchi.bookshelf.interfaces.book.BookController.java

@RequestMapping(value = { "/store" }, method = RequestMethod.POST)
public String store(@ModelAttribute StoreForm form, final Model model) {
    setting(model);//from w w w  . j av  a 2 s  . c o m

    if (BookshelfUtil.isBlank(form.getTitle()) || form.getFile().isEmpty()) {
        model.addAttribute("form", form);

        final List<SeriesEntity> seriesList = viewerService.getSeriesList();
        model.addAttribute("seriesList", seriesList);

        return "/book/store";
    }

    File tmpDir = new File("tmp");
    tmpDir.mkdirs();

    List<ContentEntity> files = new ArrayList<ContentEntity>();

    byte[] buf = new byte[1024];
    try (ZipInputStream zipStream = new ZipInputStream(form.getFile().getInputStream(),
            Charset.forName("MS932"))) {
        for (ZipEntry entry = zipStream.getNextEntry(); entry != null; entry = zipStream.getNextEntry()) {
            if (entry.isDirectory())
                continue;

            String id = BookshelfUtil.generateUUID();
            File tmpFile = Paths.get(tmpDir.getAbsolutePath(), id).toFile();
            OutputStream oStream = new FileOutputStream(tmpFile);

            int size = -1;
            while (0 <= (size = zipStream.read(buf, 0, 1024))) {
                oStream.write(buf, 0, size);
            }

            oStream.close();

            Metadata metadata = ImageMetadataReader.readMetadata(tmpFile);
            for (Directory directory : metadata.getDirectories()) {
                for (Tag tag : directory.getTags()) {
                    System.out.format("[%s] - %s = %s", directory.getName(), tag.getTagName(),
                            tag.getDescription());
                }
                if (directory.hasErrors()) {
                    for (String error : directory.getErrors()) {
                        System.err.format("ERROR: %s", error);
                    }
                }
            }

            BufferedImage img = ImageIO.read(tmpFile);
            System.out.println(String.format("%d / %d", img.getWidth(), img.getHeight()));

            String[] ss = entry.getName().split("/");
            files.add(new ContentEntity(ss[ss.length - 1], tmpFile, img.getWidth(), img.getHeight()));
        }
    } catch (ImageProcessingException ex) {

    } catch (IOException ex) {

    }

    bookshelfService.createBook(form.getTitle(), form.getSeries(), files);

    return "/book/store";
}

From source file:edu.umass.cs.iesl.pdf2meta.cli.extract.pdfbox.pagedrawer.BeginInlineImage.java

/**
 * process : BI : begin inline image./*ww w.j av  a  2s.  c om*/
 * @param operator The operator that is being executed.
 * @param arguments List
 * @throws java.io.IOException If there is an error displaying the inline image.
 */
public void process(PDFOperator operator, List<COSBase> arguments) throws IOException {
    GraphicsAwarePDFStreamEngine drawer = (GraphicsAwarePDFStreamEngine) context;

    PDPage page = drawer.getPage();
    //begin inline image object
    ImageParameters params = operator.getImageParameters();
    PDInlinedImage image = new PDInlinedImage();
    image.setImageParameters(params);
    image.setImageData(operator.getImageData());
    BufferedImage awtImage = image.createImage(context.getColorSpaces());

    if (awtImage == null) {
        log.warn("BeginInlineImage.process(): createImage returned NULL");
        return;
    }
    int imageWidth = awtImage.getWidth();
    int imageHeight = awtImage.getHeight();
    double pageHeight = drawer.getPageSize().getHeight();

    Matrix ctm = drawer.getGraphicsState().getCurrentTransformationMatrix();
    int pageRotation = page.findRotation();

    AffineTransform ctmAT = ctm.createAffineTransform();
    ctmAT.scale(1f / imageWidth, 1f / imageHeight);
    Matrix rotationMatrix = new Matrix();
    rotationMatrix.setFromAffineTransform(ctmAT);
    // calculate the inverse rotation angle
    // scaleX = m00 = cos
    // shearX = m01 = -sin
    // tan = sin/cos
    double angle = Math.atan(ctmAT.getShearX() / ctmAT.getScaleX());
    Matrix translationMatrix = null;
    if (pageRotation == 0 || pageRotation == 180) {
        translationMatrix = Matrix.getTranslatingInstance((float) (Math.sin(angle) * ctm.getXScale()),
                (float) (pageHeight - 2 * ctm.getYPosition() - Math.cos(angle) * ctm.getYScale()));
    } else if (pageRotation == 90 || pageRotation == 270) {
        translationMatrix = Matrix.getTranslatingInstance((float) (Math.sin(angle) * ctm.getYScale()),
                (float) (pageHeight - 2 * ctm.getYPosition()));
    }
    rotationMatrix = rotationMatrix.multiply(translationMatrix);
    rotationMatrix.setValue(0, 1, (-1) * rotationMatrix.getValue(0, 1));
    rotationMatrix.setValue(1, 0, (-1) * rotationMatrix.getValue(1, 0));
    AffineTransform at = new AffineTransform(rotationMatrix.getValue(0, 0), rotationMatrix.getValue(0, 1),
            rotationMatrix.getValue(1, 0), rotationMatrix.getValue(1, 1), rotationMatrix.getValue(2, 0),
            rotationMatrix.getValue(2, 1));
    drawer.drawImage(awtImage, at);
}

From source file:com.skcraft.launcher.swing.InstanceTableModel.java

private ImageIcon buildDownloadIcon(BufferedImage instanceIcon) {
    try {/*from  w  w w  .j  a  v  a 2 s.c o  m*/
        BufferedImage iconBg = instanceIcon;
        BufferedImage iconFg = ImageIO.read(Launcher.class.getResource("download_icon_overlay.png"));
        BufferedImage iconCombined = new BufferedImage(iconBg.getWidth(), iconBg.getHeight(),
                BufferedImage.TYPE_INT_ARGB);
        Graphics2D canvas = iconCombined.createGraphics();
        canvas.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
        canvas.drawImage(iconBg, 0, 0, null);
        canvas.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f));
        canvas.drawImage(iconFg, iconBg.getWidth() - iconFg.getWidth(), iconBg.getHeight() - iconFg.getHeight(),
                null);
        canvas.dispose();
        return new ImageIcon(iconCombined);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}