Example usage for javax.swing ImageIcon getIconHeight

List of usage examples for javax.swing ImageIcon getIconHeight

Introduction

In this page you can find the example usage for javax.swing ImageIcon getIconHeight.

Prototype

public int getIconHeight() 

Source Link

Document

Gets the height of the icon.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {

    ImageIcon icon = new ImageIcon("image.gif");
    icon.setDescription("Description of Image");

    System.out.println(icon.getIconHeight());
}

From source file:ImageUtil.java

/**
 * get image orientation type//from  ww  w.j  ava 2 s. c om
 * @param imageFile
 * @return 0:Landscape, 1:Portrait
 */
public static int getOrientation(File imageFile) {
    int result = 0;
    ImageIcon image = new ImageIcon(imageFile.getPath());
    if (image.getIconWidth() > image.getIconHeight()) {
        result = 0;
    } else {
        result = 1;
    }
    image = null;
    return result;
}

From source file:ImageUtil.java

/**
 * get fixing preview image rsize <br/>
 * Exif not apply: calculate by formula: iHeight/iWidth*rsize < (lbHeight-10)
 * Exif apply: calculate by formula: iHeight/iWidth*rsize < (lbHeight-80-10)
 * @param imageFile//  w  w w  . j  a v a2s  . c  o m
 * @param lbWidth
 * @param lbHeight
 * @param applyExif
 * @return
 */
public static int getFixedPreviewSize(File imageFile, int lbHeight, boolean applyExif) {
    int rsize = 0;
    ImageIcon image = new ImageIcon(imageFile.getPath());
    int iHeight = image.getIconHeight();
    int iWidth = image.getIconWidth();
    image = null;
    if (iHeight > iWidth) {
        if (!applyExif) {
            rsize = lbHeight - 10;
        } else {
            rsize = lbHeight - 90;
        }
    } else {
        if (!applyExif) {
            rsize = (lbHeight - 10) * iWidth / iHeight;
        } else {
            rsize = (lbHeight - 90) * iWidth / iHeight;
        }
    }
    return rsize;
}

From source file:ImageUtil.java

/**
 * get image thumbnail/*  ww  w.  jav  a2  s  .  c om*/
 * @param imageFile
 */
public static ImageIcon getImageThumbnail(File imageFile, int width, int height) {
    ImageIcon thumbnail = null;
    if (imageFile != null && imageFile.isFile()) {
        ImageIcon tmpIcon = new ImageIcon(imageFile.getPath());
        if (tmpIcon != null) {
            if (tmpIcon.getIconWidth() > width) {
                int targetHeight = width / tmpIcon.getIconWidth() * tmpIcon.getIconHeight();
                if (targetHeight > height) {
                    targetHeight = height;
                } else {
                    targetHeight = -1;
                }
                thumbnail = new ImageIcon(
                        tmpIcon.getImage().getScaledInstance(width, targetHeight, Image.SCALE_AREA_AVERAGING));
            } else {
                thumbnail = tmpIcon;
            }
        }
    }
    return thumbnail;
}

From source file:com.uksf.mf.core.utility.loaders.ImageLoad.java

/**
 * Changes colour of all non-transparent pixels for given image to given colour
 * @param image - image to change colours in
 * @param newColour colour to change to// ww w. ja v a 2s  .  c o m
 * @return image with changed colours
 */
private static ImageIcon changeImageColour(ImageIcon image, int newColour) {
    LogHandler.logSeverity(INFO, "Converting image: " + image + " colour to: " + newColour);
    BufferedImage bufferedImage = new BufferedImage(image.getIconWidth(), image.getIconHeight(),
            BufferedImage.TYPE_INT_ARGB);
    Graphics graphics = bufferedImage.createGraphics();
    image.paintIcon(null, graphics, 0, 0);
    graphics.dispose();
    for (int x = 0; x < bufferedImage.getWidth(); x++) {
        for (int y = 0; y < bufferedImage.getHeight(); y++) {
            int colour = bufferedImage.getRGB(x, y);
            colour = (((colour >> 24) & 0xff) << 24) | (((colour & 0x00ff0000) >> 16) << 16)
                    | (((colour & 0x0000ff00) >> 8) << 8) | (colour & 0x000000ff);
            if (colour != COLOUR_TRANSPARENT.getRGB()) {
                newColour = (((colour >> 24) & 0xff) << 24) | (((newColour & 0x00ff0000) >> 16) << 16)
                        | (((newColour & 0x0000ff00) >> 8) << 8) | (newColour & 0x000000ff);
                bufferedImage.setRGB(x, y, newColour);
            }
        }
    }
    return new ImageIcon(bufferedImage);
}

From source file:Main.java

/** Constructs a JButton with an icon from the given file id. */
public static JButton makeButton(final Object owner, final String id, final String altText, final int wpad,
        final int hpad) {
    final URL url = owner.getClass().getResource(id);
    ImageIcon icon = null;
    if (url != null)
        icon = new ImageIcon(url);
    JButton button;/*from www . j a v  a  2 s  .  co  m*/
    if (icon == null)
        button = new JButton(altText);
    else {
        button = new JButton(icon);
        button.setPreferredSize(new Dimension(icon.getIconWidth() + wpad, icon.getIconHeight() + hpad));
    }
    return button;
}

From source file:juicebox.tools.utils.juicer.apa.APAPlotter.java

/**
 * Calculate raw dimensions of image/*from ww w  .  j a v a2  s.  c o m*/
 *
 * @param image
 * @return dimension (x,y) size of image in pixels
 */
private static Dimension getImageDimensions(Image image) {
    ImageIcon icon = new ImageIcon(image);
    return new Dimension(icon.getIconWidth(), icon.getIconHeight());
}

From source file:Main.java

/** Constructs a JToggleButton with an icon from the given file id. */
public static JToggleButton makeToggleButton(final Object owner, final String id, final String altText,
        final int wpad, final int hpad) {
    final URL url = owner.getClass().getResource(id);
    ImageIcon icon = null;
    if (url != null)
        icon = new ImageIcon(url);
    JToggleButton button;//  w  w w.j  ava2  s. c o  m
    if (icon == null)
        button = new JToggleButton(altText);
    else {
        button = new JToggleButton(icon);
        button.setPreferredSize(new Dimension(icon.getIconWidth() + wpad, icon.getIconHeight() + hpad));
    }
    return button;
}

From source file:de.fhg.igd.swingrcp.SwingRCPUtilities.java

/**
 * Create a SWT Image from an {@link ImageIcon}
 * //  w w w . jav  a  2s .co  m
 * {@link "http://www.eclipseproject.de/modules.php?name=Forums&file=viewtopic&t=5489"}
 * {@link "http://www.9php.com/FAQ/cxsjl/java/2007/11/5033330101296.html"}
 * 
 * @param icon the {@link ImageIcon}
 * @return the SWT {@link ImageData}
 */
public static ImageData convertToSWT(ImageIcon icon) {
    BufferedImage img = GraphicsUtilities.createCompatibleTranslucentImage(icon.getIconWidth(),
            icon.getIconHeight());

    img.getGraphics().drawImage(icon.getImage(), 0, 0, null);

    return convertToSWT(img);
}

From source file:com.reydentx.core.common.PhotoUtils.java

public static byte[] waterMarkJPG(String baseImagePath, String waterMartPath) {
    try {/*from   ww w.  j  a v  a2 s .co  m*/
        File origFile = new File(baseImagePath);
        ImageIcon icon = new ImageIcon(origFile.getPath());
        BufferedImage bufferedImage = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(),
                BufferedImage.TYPE_INT_RGB);
        Graphics graphics = bufferedImage.getGraphics();
        graphics.drawImage(icon.getImage(), 0, 0, null);

        ImageIcon png = new ImageIcon(waterMartPath);
        graphics.drawImage(png.getImage(), 0, 0, null);

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ImageIO.write(bufferedImage, "jpg", baos);
        baos.flush();
        byte[] imageInByte = baos.toByteArray();

        return imageInByte;
    } catch (IOException e) {
        e.printStackTrace();
    }

    return null;
}