private static BufferedImage readImage(final ImageIcon imageIcon) { final Image tmpImage = imageIcon.getImage(); final BufferedImage image = new BufferedImage(imageIcon.getIconWidth(), imageIcon.getIconHeight(), BufferedImage.TYPE_INT_ARGB); image.getGraphics().drawImage(tmpImage, 0, 0, null); tmpImage.flush(); return image; }
@Override public void paintIcon(Component c, Graphics g, int x, int y) { genderIcon.paintIcon(c, g, x, y); int innerX = x + genderIcon.getIconWidth(); int equipmentIconHeight = genderIcon.getIconHeight(); for (int i = 0; i < equipmentColorList.size(); i++) { g.setColor(equipmentColorList.get(i)); g.fillRect(innerX + 1, y + 1, EQUIPMENT_ICON_WIDTH - 2, equipmentIconHeight - 2); g.setColor(TangoColorFactory.ALUMINIUM_5); g.drawRect(innerX + 1, y + 1, EQUIPMENT_ICON_WIDTH - 2, equipmentIconHeight - 2); innerX += EQUIPMENT_ICON_WIDTH; } }
protected void paintComponent(Graphics g) { super.paintComponent(g); setBackground(Color.WHITE); // draw logo g.drawImage(logoIcon.getImage(), getWidth()/2 - logoIcon.getIconWidth()/2, getHeight()/2 - logoIcon.getIconHeight()/2, logoIcon.getIconWidth(), logoIcon.getIconHeight(), logoIcon.getImageObserver()); drawVersionString(g, logoIcon); }
ImageIcon tempIcon = new ImageIcon(tempImage); inputImage = new BufferedImage(tempIcon.getIconWidth(), tempIcon.getIconHeight(), BufferedImage.TYPE_INT_ARGB); inputImage.getGraphics().drawImage(tempImage, 0, 0, null);
ImageIcon ii = new ImageIcon("path-to-image"); int scale = 2; // 2 times smaller int width = ii.getIconWidth(); int newWidth = width / scale; yourComponent.setIcon(new ImageIcon(ii.getImage().getScaledInstance(newWidth, -1, java.awt.Image.SCALE_SMOOTH)));
JLabel label2 = new JLabel("Address :", JLabel.LEFT); ImageIcon icon = new ImageIcon("images/myIcon.gif"); if (icon.getIconWidth() == -1) { JOptionPane.showMessageDialog(null, "No image!", "Gahh!", JOptionPane.ERROR_MESSAGE); } else { label2.setIcon(icon); }
@Override public void paintIcon(Component c, Graphics g, int x, int y) { int dwidth = img.getIconWidth() / width; int nx = (this.num % dwidth) * this.width; int ny = (this.num / dwidth) * this.height; g.drawImage(this.img.getImage(), x, y, x + this.width, y + this.height, nx, ny, nx + this.width, ny + this.height, c); } }
private ImageIcon concatenateImages(ImageIcon left, ImageIcon right) { // Merge icons BufferedImage image = new BufferedImage(left.getIconWidth() + right.getIconWidth(), Math.max(left.getIconHeight(), right.getIconHeight()), BufferedImage.TYPE_INT_ARGB); Graphics g = image.getGraphics(); g.drawImage(left.getImage(), 0, 0, null); g.drawImage(right.getImage(), left.getIconWidth(), 0, null); return new ImageIcon(image); }
image.getIconWidth(), image.getIconHeight() ); info.setBounds( 200, 00, 50, 40 ); JFrame frame = new JFrame(); frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); frame.add( new MyClass( new ImageIcon("logo.png") ) ); frame.pack(); frame.setVisible( true );
ImageIcon icon=null; ImageIcon imageicon = new ImageIcon("C:\\Winter.jpg"); if (imageicon != null) { if (imageicon.getIconWidth() > 60) { System.out.println(jLabel1.getWidth()); icon = new ImageIcon(imageicon.getImage().getScaledInstance(26, -1, Image.SCALE_DEFAULT)); } else { icon = imageicon; } jLabel1.setIcon((Icon) icon);
@Override public void paintComponent(Graphics g) { final Dimension size = pane.getSize(); int x = (size.width - icon.getIconWidth()) / 2; int y = (size.height - icon.getIconHeight()) / 2; // Approach 1: Dispaly image at at full size g.setColor(Color.white); g.fillRect(0, 0, size.width, size.height); g.drawImage(icon.getImage(), x, y, null); setOpaque(false); super.paintComponent(g); }
@Override public void serialize(ImageIcon vi, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { synchronized (vi) { BufferedImage v = new BufferedImage( vi.getIconWidth(), vi.getIconHeight(), BufferedImage.TYPE_INT_RGB); Graphics g = v.createGraphics(); // paint the Icon to the BufferedImage. vi.paintIcon(null, g, 0, 0); g.dispose(); byte [] data = Images.encode(v); jgen.writeStartObject(); jgen.writeStringField("type", "ImageIcon"); jgen.writeObjectField("imageData", data); jgen.writeNumberField("width", v.getWidth()); jgen.writeNumberField("height", v.getHeight()); jgen.writeEndObject(); } }
class Cr extends JPanel{ //change here ('\\' is the escape sequence for '\') : ImageIcon image = new ImageIcon("C:\\Users\\Public\\Pictures\\Sample Pictures\\Desert.jpg"); public void paint( Graphics g ) { Dimension d = getSize(); for( int x = 0; x < d.width; x += image.getIconWidth() ) for( int y = 0; y < d.height; y += image.getIconHeight() ) g.drawImage( image.getImage(), x, y, null, null ); super.paint(g); } }
public JRendererStatusBarItem(MapPane mapPane) { super("Busy", false); busyIcon = new ImageIcon(JRendererStatusBarItem.class.getResource(BUSY_IMAGE)); idleIcon = new ImageIcon(JRendererStatusBarItem.class.getResource(IDLE_IMAGE)); renderLabel.setMinimumSize( new Dimension( busyIcon.getIconWidth() + insets.left + insets.right, busyIcon.getIconHeight() + insets.top + insets.bottom));
public static ImageIcon addErrorOverlay(final ImageIcon imageIcon) { final int offset = adjuster.adjust(4); final int iconWidth = imageIcon.getIconWidth(); final int decorationSize = iconWidth / 2; final Image errorImage = _imageManager.getImage(STATUS_ERROR, decorationSize); final BufferedImage bufferedImage = new BufferedImage(iconWidth + offset, iconWidth + offset, BufferedImage.TYPE_INT_ARGB); bufferedImage.getGraphics().drawImage(imageIcon.getImage(), offset, 0, null); bufferedImage.getGraphics().drawImage(errorImage, 0, iconWidth + offset - decorationSize, null); return new ImageIcon(bufferedImage); }
int y = translator.translateLatitudeToY(depot.getLocation().getLatitude()); g.fillRect(x - 2, y - 2, 5, 5); g.drawImage(depotImageIcon.getImage(), x - depotImageIcon.getIconWidth() / 2, y - 2 - depotImageIcon.getIconHeight(), imageObserver); int vehicleInfoHeight = vehicleImageIcon.getIconHeight() + 2 + TEXT_SIZE; g.drawImage(vehicleImageIcon.getImage(), x + 1, (ascending ? y - vehicleInfoHeight - 1 : y + 1), imageObserver); g.drawString(load + " / " + vehicle.getCapacity(),
public Dimension getPreferredSize() { final Dimension size = super.getPreferredSize(); size.width = icons.getIconWidth(); size.height = icons.getIconHeight(); return size; } }
ImageIcon image = new ImageIcon("mysticky.png"); @Override public void paintComponent(Graphics g) { super.paintComponent(g); for(ImagePanelImage nextim : backgroundImages) { g.drawImage(image.getImage(), 0, 0, image.getIconWidth(), image.getIconHeight(), this); } }
@Override public void customize(JList list, ImageAsset imageAsset, int index, boolean selected, boolean hasFocus) { LayeredIcon layeredIcon = new LayeredIcon(2); File imageFile = controller.getThumbnailFile(imageAsset); if (imageFile != null && imageFile.exists()) { final ImageIcon icon = new ImageIcon(imageFile.getAbsolutePath()); layeredIcon.setIcon(icon, 1, (- icon.getIconWidth() + EMPTY_ICON.getIconWidth())/2, (EMPTY_ICON.getIconHeight() - icon.getIconHeight())/2); } setIcon(layeredIcon); final String searchQuery = comboboxSpeedSearch.getEnteredPrefix(); if (searchQuery != null && searchQuery.trim().length() > 0 && imageAsset.getName().contains(searchQuery)) { setBackground(JBColor.YELLOW); } else { setBackground(null); } } }
/** * Gets the image and shows as a thumbnail * */ public void loadImage(ImageIcon icon) { ImageIcon tmpIcon = icon; if (tmpIcon != null) { if (tmpIcon.getIconWidth() > 90) { thumbnail = new ImageIcon(tmpIcon.getImage().getScaledInstance(90, -1, Image.SCALE_DEFAULT)); } else { thumbnail = tmpIcon; } imagePreview.setIcon(thumbnail); } }