List of usage examples for javax.swing ImageIcon getIconWidth
public int getIconWidth()
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.getIconWidth()); }
From source file:ImageUtil.java
/** * get image orientation type/*from w w w . ja v a 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 image thumbnail// www .j a va2 s . c o m * @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: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//from ww w .j a va 2s . 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: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/*from w w w. j a v a 2 s. com*/ * @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;/*ww w.j a v a 2s . c om*/ 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 w w w . j a v a 2s . co 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;//from w w w .j a v a 2 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} * /*from w ww . ja v a 2 s . c o 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:jshm.gui.GuiUtil.java
public final static javax.swing.ImageIcon resizeIcon(ImageIcon icon, float scale) { return resizeIcon(icon, (int) (scale * icon.getIconWidth()), (int) (scale * icon.getIconHeight())); }