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:eu.novait.imagerenamer.model.ImageFile.java

private void createThumbnail() {
    try {/*w ww.jav a  2s  .  c  o m*/
        BufferedImage tmp = ImageIO.read(this.filepath);
        int tmpW = tmp.getWidth();
        int tmpH = tmp.getHeight();
        double ratio = (double) tmpW / (double) tmpH;
        int w = 400;
        int h = (int) Math.round(w / ratio);
        BufferedImage bi = getCompatibleImage(w, h);
        Graphics2D g2d = bi.createGraphics();
        double xScale = (double) w / tmp.getWidth();
        double yScale = (double) h / tmp.getHeight();
        AffineTransform at = AffineTransform.getScaleInstance(xScale, yScale);
        g2d.drawRenderedImage(tmp, at);
        g2d.dispose();
        this.setThumbnail(bi);
    } catch (IOException ex) {
        Logger.getLogger(ImageFile.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.github.cherimojava.orchidae.controller.PictureController.java

/**
 * creates the Thumbnail for the given picture and stores it on the disk
 * /* w ww.j a  va  2  s. c  om*/
 * @param id
 * @param image
 * @param type
 */
private void createSmall(String id, BufferedImage image, String type) {
    int height = image.getHeight();
    int width = image.getWidth();
    double scale = maxHeight / (double) height;
    BufferedImage thumbnail = Scalr.resize(image, Scalr.Method.ULTRA_QUALITY,
            ((Double) (width * scale)).intValue(), ((Double) (height * scale)).intValue(), Scalr.OP_ANTIALIAS);
    try {
        ImageIO.write(thumbnail, type, fileUtil.getFileHandle(id + "_s"));
    } catch (IOException e) {
        LOG.error("failed to create thumbnail for picture", e);
    }
}

From source file:no.dusken.aranea.admin.control.ImageDimensionController.java

public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) {

    // ignore the request, this is plain work
    for (Image image : imageService.getImages()) {
        File file = imageUtils.getImageFile(image);
        image.setFileSize(file.length());
        BufferedImage rendImage;
        try {//from   www . ja v a  2  s  .c  o  m
            rendImage = ImageIO.read(file);
        } catch (IOException e) {
            log.error("Could not read image {} {}", image, e);
            continue;
        }
        image.setHeight(rendImage.getHeight());
        image.setWidth(rendImage.getWidth());

        imageService.saveOrUpdate(image);
    }
    return new ModelAndView("redirect:/");
}

From source file:com.github.cmisbox.ui.BaseFrame.java

public Image getImage(String resource, Integer height, Integer width) {
    try {//from  w ww .ja v a2 s  .  c  om

        BufferedImage image = ImageIO.read(this.getClass().getResource(resource));

        if ((height != null) && (width != null)
                && ((image.getHeight() != height) || (image.getWidth() != width))) {
            return image.getScaledInstance(width, height, Image.SCALE_SMOOTH);
        }

        return image;
    } catch (IOException e1) {
        this.log.error(e1);
    }
    return null;
}

From source file:javafx1.Testpics.java

private void bildSchleife() {
    File f = new File("F:/NetBeansProjekte/pictures");
    File[] fileArray = f.listFiles();
    java.util.Arrays.sort(fileArray);
    for (File file : fileArray) {
        try {/* w  w w  .jav  a2  s . com*/
            System.out.println("file: " + file.getCanonicalPath());
            File outputfile = new File(file.getCanonicalPath() + ".jpg");
            BufferedImage bi = ImageIO.read(file);
            System.out.println(" enc" + encodeToString(bi, "jpg"));
            ImageIO.write(bi, "jpg", outputfile);
            bi = ImageIO.read(outputfile);
            System.out.println(" w" + bi.getWidth() + " h" + bi.getHeight());
            byte[] data = ((DataBufferByte) bi.getRaster().getDataBuffer()).getData();
            // System.out.println(new String(data));
            byte[] x = Base64.encodeBase64URLSafe(data);
            System.out.println("x" + new String(x));
            String b64 = Base64.encodeBase64String(data);
            System.out.println("64" + b64);

            //                byte[] backToBytes = Base64.decodeBase64(base64String);
            //                InputStream in = new ByteArrayInputStream(backToBytes);
            //                BufferedImage bi;
            //                bi = ImageIO.read(in);
            //byte[] xx = base64String.getBytes(StandardCharsets.UTF_8);
            // bild, wie es von http kommt
            //                RunPic rp = new RunPic(this, data);
            //                Platform.runLater(rp);
            try {
                Thread.sleep(50);
                break;
            } catch (InterruptedException ex) {
                Logger.getLogger(JavaFX1.class.getName()).log(Level.SEVERE, null, ex);
            }

        } catch (IOException ex) {
            Logger.getLogger(JavaFX1.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:org.esa.beam.visat.toolviews.stat.XYImagePlot.java

public void setImage(BufferedImage image) {
    synchronized (imageLock) {
        this.image = image;
        if (image != null && imageDataBounds == null) {
            setImageDataBounds(new Rectangle(0, 0, image.getWidth(), image.getHeight()));
        }/*from  w w  w. ja  v a2 s.c o m*/
    }
}

From source file:de.ailis.wlandsuite.image.PaletteImage.java

/**
 * Creates a diff between this picture and the specified one and returns it
 * in form of a transparent ega image.//from  ww w. j  a  va  2 s .c  o m
 * 
 * @param image
 *            The other image to create a diff for
 * @return The diff as a transparent EGA image
 */

public TransparentEgaImage getDiff(final BufferedImage image) {
    final int aw = getWidth();
    final int ah = getHeight();
    final int bw = image.getWidth();
    final int bh = image.getHeight();
    final TransparentEgaImage diff = new TransparentEgaImage(bw, bh);
    for (int y = 0; y < bh; y++) {
        for (int x = 0; x < bw; x++) {
            if (y >= ah || x >= aw || getRGB(x, y) != image.getRGB(x, y))
                diff.setRGB(x, y, image.getRGB(x, y));
        }
    }
    return diff;
}

From source file:bjerne.gallery.service.impl.ImageResizeServiceImpl.java

@Override
public void resizeImage(File origImage, File newImage, int width, int height) throws IOException {
    LOG.debug("Entering resizeImage(origImage={}, width={}, height={})", origImage, width, height);
    long startTime = System.currentTimeMillis();
    InputStream is = new BufferedInputStream(new FileInputStream(origImage));
    BufferedImage i = ImageIO.read(is);
    IOUtils.closeQuietly(is);//  ww w .  ja  v  a  2s .c o m
    BufferedImage scaledImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    int origWidth = i.getWidth();
    int origHeight = i.getHeight();
    LOG.debug("Original size of image - width: {}, height={}", origWidth, height);
    float widthFactor = ((float) origWidth) / ((float) width);
    float heightFactor = ((float) origHeight) / ((float) height);
    float maxFactor = Math.max(widthFactor, heightFactor);
    int newHeight, newWidth;
    if (maxFactor > 1) {
        newHeight = (int) (((float) origHeight) / maxFactor);
        newWidth = (int) (((float) origWidth) / maxFactor);
    } else {
        newHeight = origHeight;
        newWidth = origWidth;
    }
    LOG.debug("Size of scaled image will be: width={}, height={}", newWidth, newHeight);
    int startX = Math.max((width - newWidth) / 2, 0);
    int startY = Math.max((height - newHeight) / 2, 0);
    Graphics2D scaledGraphics = scaledImage.createGraphics();
    scaledGraphics.setColor(backgroundColor);
    scaledGraphics.fillRect(0, 0, width, height);
    scaledGraphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
            RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    scaledGraphics.drawImage(i, startX, startY, newWidth, newHeight, null);
    OutputStream resultImageOutputStream = new BufferedOutputStream(FileUtils.openOutputStream(newImage));
    String extension = FilenameUtils.getExtension(origImage.getName());
    ImageIO.write(scaledImage, extension, resultImageOutputStream);
    IOUtils.closeQuietly(resultImageOutputStream);
    long duration = System.currentTimeMillis() - startTime;
    LOG.debug("Time in milliseconds to scale {}: {}", newImage.toString(), duration);
}

From source file:com.github.pitzcarraldo.dissimilar.Dissimilar.java

/**
 * Compare two files, according to parameters passed via command line
 * @param pOne first file to compare//from  www .j a  v a 2  s  . c o m
 * @param pTwo second file to compare
 * @param pHeatMapImage file to save ssim heat map image to
 * @param pCalcSSIM whether or not to calculate ssim
 * @param pCalcPSNR whether or not to calculate psnr
 */
private static void compare(final File pOne, final File pTwo, final String pHeatMapImage,
        final boolean pCalcSSIM, final boolean pCalcPSNR) {

    //just load the images once and use the internal methods for calculating ssim/psnr
    long time = System.currentTimeMillis();
    BufferedImage imageOne = null;
    try {
        imageOne = Imaging.getBufferedImage(pOne);
    } catch (IOException e) {
        printError(pOne, false, false, pTwo, false);
        return;
    } catch (NullPointerException e) {
        printError(pOne, false, false, pTwo, false);
        return;
    } catch (ImageReadException e) {
        printError(pOne, false, false, pTwo, false);
        return;
    }
    final long oneLoadTime = System.currentTimeMillis() - time;
    //getRGB only returns 8 bits per component, so what about 16-bit images?
    final int[] oneA = imageOne.getRGB(0, 0, imageOne.getWidth(), imageOne.getHeight(), null, 0,
            imageOne.getWidth());
    final int width = imageOne.getWidth();
    final int height = imageOne.getHeight();
    final boolean greyscale = (imageOne.getType() == BufferedImage.TYPE_BYTE_GRAY
            || imageOne.getType() == BufferedImage.TYPE_USHORT_GRAY);
    imageOne = null;
    time = System.currentTimeMillis();
    BufferedImage imageTwo = null;
    try {
        imageTwo = Imaging.getBufferedImage(pTwo);
    } catch (IOException e) {
        printError(pOne, true, true, pTwo, false);
        return;
    } catch (NullPointerException e) {
        printError(pOne, true, true, pTwo, false);
        return;
    } catch (ImageReadException e) {
        printError(pOne, true, true, pTwo, false);
        return;
    }
    final long twoLoadTime = System.currentTimeMillis() - time;

    //getRGB only returns 8 bits per component, so what about 16-bit images?
    final int[] twoA = imageTwo.getRGB(0, 0, imageTwo.getWidth(), imageTwo.getHeight(), null, 0,
            imageTwo.getWidth());
    imageTwo = null;

    //calculate psnr if wanted
    time = System.currentTimeMillis();
    double psnr = 0;
    long psnrCalc = 0;
    if (pCalcPSNR) {
        psnr = calcPSNR(oneA, twoA, greyscale);
        psnrCalc = System.currentTimeMillis() - time;
    }

    //calculate ssim if wanted
    time = System.currentTimeMillis();
    List<Double> ssimMin = new LinkedList<Double>();
    List<Double> ssimVariance = new LinkedList<Double>();
    double ssim = 0;
    long ssimCalc = 0;
    if (pCalcSSIM) {
        ssim = calcSSIM(oneA, twoA, width, height, greyscale, pHeatMapImage, ssimMin, ssimVariance);
        ssimCalc = System.currentTimeMillis() - time;
    }

    System.out.println("<dissimilar version=\"" + version + "\">");
    System.out.println("     <file loadTimeMS=\"" + oneLoadTime + "\">" + pOne + "</file>");
    System.out.println("     <file loadTimeMS=\"" + twoLoadTime + "\">" + pTwo + "</file>");
    if (pCalcSSIM) {
        System.out.println("     <ssim calcTimeMS=\"" + ssimCalc + "\">");
        if (ssim > 0) {
            System.out.println("          <mean>" + new DecimalFormat("0.0000000").format(ssim) + "</mean>");
            System.out.println(
                    "          <min>" + new DecimalFormat("0.0000000").format(ssimMin.get(0)) + "</min>");
            System.out.println("          <variance>"
                    + new DecimalFormat("0.0000000").format(ssimVariance.get(0)) + "</variance>");
        } else {
            System.out.println("failed");
        }
        System.out.println("     </ssim>");
    }
    if (pCalcPSNR) {
        System.out.println("     <psnr calcTimeMS=\"" + psnrCalc + "\">"
                + new DecimalFormat("0.0000").format(psnr) + "</psnr>");
    }
    System.out.println("</dissimilar>");

}

From source file:hudson.jbpm.PluginImpl.java

/**
 * Draws a JPEG for a process definition
 * //w  w  w  .  j av  a2s .  c o m
 * @param req
 * @param rsp
 * @param processDefinition
 * @throws IOException
 */
public void doProcessDefinitionImage(StaplerRequest req, StaplerResponse rsp,
        @QueryParameter("processDefinition") long processDefinition) throws IOException {

    JbpmContext context = getCurrentJbpmContext();
    ProcessDefinition definition = context.getGraphSession().getProcessDefinition(processDefinition);
    FileDefinition fd = definition.getFileDefinition();
    byte[] bytes = fd.getBytes("processimage.jpg");
    rsp.setContentType("image/jpeg");
    ServletOutputStream output = rsp.getOutputStream();

    BufferedImage loaded = ImageIO.read(new ByteArrayInputStream(bytes));
    BufferedImage aimg = new BufferedImage(loaded.getWidth(), loaded.getHeight(), BufferedImage.TYPE_INT_RGB);
    Graphics2D g = aimg.createGraphics();
    g.drawImage(loaded, null, 0, 0);
    g.dispose();
    ImageIO.write(aimg, "jpg", output);
    output.flush();
    output.close();
}