List of usage examples for javax.imageio ImageIO read
public static BufferedImage read(ImageInputStream stream) throws IOException
From source file:Main.java
public static void main(String[] args) throws IOException { URL url = new URL("http://www.java2s.com/style/download.png"); BufferedImage im = ImageIO.read(url); URL url2 = new URL("http://www.java2s.com/style/download.png"); BufferedImage im2 = ImageIO.read(url2); Graphics2D g = im.createGraphics(); g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f)); g.drawImage(im2, (im.getWidth() - im2.getWidth()) / 2, (im.getHeight() - im2.getHeight()) / 2, null); g.dispose();/* w w w . jav a 2s . c o m*/ display(im); ImageIO.write(im, "jpeg", new File("output.jpeg")); }
From source file:Main.java
public static void main(String[] argv) throws Exception { InputStream is = new BufferedInputStream(new FileInputStream("s.gif")); Image image = ImageIO.read(is); JFrame frame = new JFrame(); JLabel label = new JLabel(new ImageIcon(image)); frame.getContentPane().add(label, BorderLayout.CENTER); frame.pack();// ww w .ja va2 s . c o m frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) throws Exception { URL url = new URL("http://www.java2s.com/style/download.png"); final BufferedImage image = ImageIO.read(url); int x = 50;/* w ww. j av a 2 s .c om*/ final Image crop = image.getSubimage(x, 0, image.getWidth() - x, image.getHeight()); Runnable r = new Runnable() { @Override public void run() { JPanel gui = new JPanel(); gui.add(new JLabel(new ImageIcon(image)), BorderLayout.LINE_START); gui.add(new JLabel("java2s.com")); gui.add(new JLabel(new ImageIcon(crop)), BorderLayout.LINE_END); JOptionPane.showMessageDialog(null, gui); } }; SwingUtilities.invokeLater(r); }
From source file:Main.java
public static void main(String[] args) { try {//ww w. j a v a2 s. c om bg = ImageIO.read(new URL("http://www.java2s.com/style/download.png")); } catch (Exception ex) { System.out.println(ex); } JPanel tabPanel = new JPanel(new GridBagLayout()) { @Override protected void paintComponent(Graphics g) { super.paintComponent(g); g.drawImage(bg, 0, 0, getWidth(), getHeight(), this); } @Override public Dimension getPreferredSize() { return new Dimension(400, 300); } }; JPanel buttons = new JPanel(new GridLayout(4, 1, 15, 15)); buttons.setOpaque(false); for (int i = 0; i < 4; i++) { buttons.add(new JButton("Button")); } tabPanel.add(buttons); JTabbedPane tabPane = new JTabbedPane(); tabPane.add("Panel with Bachground", tabPanel); JFrame frame = new JFrame(); frame.setContentPane(tabPane); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) throws IOException { BufferedImage original = ImageIO.read(new URL("http://www.java2s.com/style/download.png")); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gd = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gd.getDefaultConfiguration(); BufferedImage rotated1 = create(original, -Math.PI / 2, gc); BufferedImage rotated2 = create(original, +Math.PI / 4, gc); BufferedImage rotated3 = create(original, Math.PI, gc); JPanel cp = new JPanel(); cp.add(new JLabel(new ImageIcon(original))); cp.add(new JLabel(new ImageIcon(rotated1))); cp.add(new JLabel(new ImageIcon(rotated2))); cp.add(new JLabel(new ImageIcon(rotated3))); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setContentPane(cp);/*from w w w . j av a 2 s . c om*/ f.pack(); f.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { //Read from an input stream InputStream is = new BufferedInputStream(new FileInputStream("source.gif")); Image image = ImageIO.read(is); JFrame frame = new JFrame(); JLabel label = new JLabel(new ImageIcon(image)); frame.getContentPane().add(label, BorderLayout.CENTER); frame.pack();//from w w w . ja va 2 s . co m frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) throws Exception { URL urlImage1 = new URL("http://www.java2s.com/style/download.png"); final Image fgImage = ImageIO.read(urlImage1); int w = fgImage.getWidth(null); int h = fgImage.getHeight(null); final BufferedImage bgImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); final BufferedImage finalImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Graphics2D g = finalImage.createGraphics(); g.drawImage(bgImage, 0, 0, null);/*from w w w . j a v a 2s.co m*/ g.drawImage(fgImage, 0, 0, null); g.dispose(); Runnable r = new Runnable() { @Override public void run() { JPanel gui = new JPanel(new GridLayout(1, 0, 5, 5)); gui.add(new JLabel(new ImageIcon(bgImage))); gui.add(new JLabel(new ImageIcon(fgImage))); gui.add(new JLabel(new ImageIcon(finalImage))); JOptionPane.showMessageDialog(null, gui); } }; SwingUtilities.invokeLater(r); }
From source file:Main.java
public static void main(String[] args) throws Exception { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); URL url = new URL("http://www.java2s.com/style/download.png"); Image image = ImageIO.read(url); ImagePanel ip = new ImagePanel(new GridLayout(4, 4, 20, 20)); ip.setPreferredSize(new Dimension(640, 480)); f.setContentPane(ip);/* w w w .java 2 s.c o m*/ f.pack(); f.setVisible(true); ip.setImage(new ImageIcon(image)); }
From source file:Main.java
public static void main(String[] args) throws Exception { BufferedImage img = ImageIO.read(new File("test.jpg")); writeJpegCompressedImage(img, "NEW.jpg"); }
From source file:Main.java
public static void main(String[] args) throws Exception { String mapUrlPath = "http://www.java2s.com/style/download.png"; URL mapUrl = new URL(mapUrlPath); BufferedImage mapImage = ImageIO.read(mapUrl); Image newMapImage = Toolkit.getDefaultToolkit() .createImage(new FilteredImageSource(mapImage.getSource(), new RedBlueSwapFilter())); ImageIcon mapIcon = new ImageIcon(mapImage); ImageIcon newMapIcon = new ImageIcon(newMapImage); JPanel imagePanel = new JPanel(); imagePanel.add(new JLabel(mapIcon)); imagePanel.add(new JLabel(newMapIcon)); JOptionPane.showMessageDialog(null, imagePanel); }