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:at.gv.egiz.pdfas.common.utils.ImageUtils.java

public static BufferedImage removeAlphaChannel(BufferedImage src) {
    //if (src.getColorModel().hasAlpha()) {
    BufferedImage image = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_INT_RGB);
    Graphics2D g = image.createGraphics();
    g.setComposite(AlphaComposite.Src);
    g.drawImage(src, 0, 0, null);/*from  w  w w.  ja  v  a 2  s.c om*/
    g.dispose();
    return image;
    //}
    //return src;
    /*
     * BufferedImage rgbImage = new BufferedImage(src.getWidth(),
     * src.getHeight(), BufferedImage.TYPE_3BYTE_BGR); for (int x = 0; x <
     * src.getWidth(); ++x) { for (int y = 0; y < src.getHeight(); ++y) {
     * rgbImage.setRGB(x, y, src.getRGB(x, y) & 0xFFFFFF); } } return
     * rgbImage;
     */
}

From source file:ImageProcessing.ImageProcessing.java

public static void processFlipVertical(BufferedImage image) {
    //Flips image vertically.
    for (int i = 0; i < image.getHeight() / 2; i++) {
        for (int j = 0; j < image.getWidth(); j++) {
            int upper_rgb = image.getRGB(j, i);
            int below_rgb = image.getRGB(j, image.getHeight() - (i + 1));
            image.setRGB(j, i, below_rgb);
            image.setRGB(j, image.getHeight() - (i + 1), upper_rgb);
        }//from  www .j  av  a 2s  . co m
    }
}

From source file:com.smash.revolance.ui.model.helper.ImageHelper.java

/**
 * diff = (img2.rgb(x,y) != img1.rgb(x,y)) ? img1.rgb() : 0
 *
 * @param img1//  w  ww . ja  v a2s . c  o  m
 * @param img2
 * @return
 * @throws IOException
 */
public static BufferedImage diffImg(BufferedImage img1, BufferedImage img2) throws IOException {
    int w = img1.getWidth();
    int h = img1.getHeight();
    int t = img1.getType();

    BufferedImage diff = new BufferedImage(w, h, t);

    if (img1.getWidth() == img2.getWidth() && img1.getHeight() == img2.getHeight()) {
        for (int x = 0; x < w; x++) {
            for (int y = 0; y < h; y++) {
                int refIntensity = img1.getRGB(x, y);
                int imgIntensity = img2.getRGB(x, y);
                if (refIntensity != imgIntensity) {
                    diff.setRGB(x, y, imgIntensity);
                } else {
                    diff.setRGB(x, y, 0);
                }
            }
        }
    }

    return diff;
}

From source file:ImageProcessing.ImageProcessing.java

public static void processFlipHorizontal(BufferedImage image) {
    //Flips image horizontally.
    for (int i = 0; i < image.getHeight(); i++) {
        for (int j = 0; j < image.getWidth() / 2; j++) {
            int left_rgb = image.getRGB(j, i);
            int right_rgb = image.getRGB(image.getWidth() - (j + 1), i);

            image.setRGB(j, i, right_rgb);
            image.setRGB(image.getWidth() - (j + 1), i, left_rgb);
        }/*from   w  w  w . j  a va  2s.  c om*/
    }
}

From source file:com.smash.revolance.ui.model.helper.ImageHelper.java

public static boolean imgEquals(File imgRef, File img) throws IOException {
    if (isCached(imgRef, img)) {
        return getComparisons(imgRef).get(img).booleanValue();
    } else if (isCached(img, imgRef)) {
        return getComparisons(img).get(imgRef).booleanValue();
    } else {/* w  ww .  j a  v  a2  s  .com*/
        BufferedImage refBI = ImageIO.read(imgRef);
        BufferedImage imgBi = ImageIO.read(img);

        int width = imgBi.getWidth();
        int height = imgBi.getHeight();

        if (refBI.getWidth() == width && refBI.getHeight() == height) {
            for (int x = 0; x < width; x++) {
                for (int y = 0; y < height; y++) {
                    int refIntensity = refBI.getRGB(x, y);
                    int imgIntensity = imgBi.getRGB(x, y);
                    if (refIntensity != imgIntensity) {
                        getComparisons(imgRef).put(img, false);
                        return false;
                    }
                }
            }
        }

        getComparisons(imgRef).put(img, true);
        return true;
    }
}

From source file:com.mycollab.mobile.ui.MobileAttachmentUtils.java

public static void saveContentsToRepo(String attachmentPath, Map<String, File> fileStores) {
    if (MapUtils.isNotEmpty(fileStores)) {
        ResourceService resourceService = AppContextUtil.getSpringBean(ResourceService.class);
        for (Map.Entry<String, File> entry : fileStores.entrySet()) {
            try {
                String fileExt = "";
                String fileName = entry.getKey();
                File file = entry.getValue();
                int index = fileName.lastIndexOf(".");
                if (index > 0) {
                    fileExt = fileName.substring(index + 1, fileName.length());
                }/* www. j ava2 s  .c o  m*/

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

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

                        BufferedImage scaledImage;

                        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);
                        scaledImage = ImageUtil.scaleImage(bufferedImage, scale);

                        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
                        ImageIO.write(scaledImage, fileExt, outStream);

                        resourceService.saveContent(constructContent(fileName, attachmentPath),
                                UserUIContext.getUsername(), new ByteArrayInputStream(outStream.toByteArray()),
                                MyCollabUI.getAccountId());
                    } catch (IOException e) {
                        LOG.error("Error in upload file", e);
                        resourceService.saveContent(constructContent(fileName, attachmentPath),
                                UserUIContext.getUsername(), new FileInputStream(fileStores.get(fileName)),
                                MyCollabUI.getAccountId());
                    }
                } else {
                    resourceService.saveContent(constructContent(fileName, attachmentPath),
                            UserUIContext.getUsername(), new FileInputStream(file), MyCollabUI.getAccountId());
                }

            } catch (FileNotFoundException e) {
                LOG.error("Error when attach content in UI", e);
            }
        }
    }
}

From source file:com.l1j5.web.common.utils.ImageUtils.java

public static void getGifImageThumbnail(BufferedInputStream stream_file, String save, String type, int w) {

    GifDecoder dec = new GifDecoder();
    AnimatedGifEncoder enc = new AnimatedGifEncoder();
    dec.read(stream_file);/*from   ww w  .  ja  v  a 2  s  . c om*/

    int cnt = dec.getFrameCount();

    int delay = 0;
    int width = 0;
    int height = 0;

    try {
        enc.start(save);
        enc.setRepeat(0);

        for (int i = 0; i < cnt; i++) {
            BufferedImage frame = dec.getFrame(i);
            delay = dec.getDelay(i);

            width = frame.getWidth();
            height = frame.getHeight();

            double ratio = (double) height / width;
            height = (int) (w * ratio);
            if (w < width) {
                width = w;
            }

            BufferedImage destimg = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
            Graphics2D g = destimg.createGraphics();

            g.drawImage(frame, 0, 0, width, height, null);
            enc.setDelay(delay);

            enc.addFrame(destimg);
        }

        enc.finish();
    } catch (Exception ex) {
        log.error(ex);
    }
}

From source file:com.tools.image.IMagicHelper.java

private static int[] getRectangle(String file) throws IOException {
    BufferedImage tmp = ImageIO.read(new File(file));
    return new int[] { tmp.getWidth(), tmp.getHeight() };
}

From source file:net.sourceforge.subsonic.controller.CoverArtController.java

public static BufferedImage scale(BufferedImage image, int width, int height) {
    int w = image.getWidth();
    int h = image.getHeight();
    BufferedImage thumb = image;/*ww  w .j av  a 2  s .co  m*/

    // For optimal results, use step by step bilinear resampling - halfing the size at each step.
    do {
        w /= 2;
        h /= 2;
        if (w < width) {
            w = width;
        }
        if (h < height) {
            h = height;
        }

        BufferedImage temp = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = temp.createGraphics();
        g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
        g2.drawImage(thumb, 0, 0, temp.getWidth(), temp.getHeight(), null);
        g2.dispose();

        thumb = temp;
    } while (w != width);

    return thumb;
}

From source file:com.l1j5.web.common.utils.ImageUtils.java

public static void getGifImageThumbnail(BufferedInputStream stream_file, String save, String type, int w,
        int h) {//from  w  w  w  .ja v  a 2s.c om

    GifDecoder dec = new GifDecoder();
    AnimatedGifEncoder enc = new AnimatedGifEncoder();
    dec.read(stream_file);

    int cnt = dec.getFrameCount();

    int delay = 0;
    int width = 0;
    int height = 0;

    try {
        enc.start(save);
        enc.setRepeat(0);

        for (int i = 0; i < cnt; i++) {
            BufferedImage frame = dec.getFrame(i);
            delay = dec.getDelay(i);

            width = frame.getWidth();
            height = frame.getHeight();
            if (w < width) {
                width = w;
            }
            if (h < height) {
                height = h;
            }

            BufferedImage destimg = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
            Graphics2D g = destimg.createGraphics();

            g.drawImage(frame, 0, 0, width, height, null);
            enc.setDelay(delay);

            enc.addFrame(destimg);
        }

        enc.finish();
    } catch (Exception ex) {
        log.error(ex);
    }
}