List of usage examples for javax.imageio ImageIO read
public static BufferedImage read(ImageInputStream stream) throws IOException
From source file:MainClass.java
public static void main(String[] args) { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice screen = ge.getDefaultScreenDevice(); if (!screen.isFullScreenSupported()) { System.out.println("Full screen mode not supported"); System.exit(1);//from ww w.j a va 2 s. c o m } try { BufferedImage loadedpic = ImageIO.read(new File("your.jpg")); screen.setFullScreenWindow(new MainClass(loadedpic)); } catch (Exception e) { System.err.println(e.getMessage()); } }
From source file:Main.java
public static void main(String[] args) throws IOException { String path = "C:/Pictures/"; JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); File folder = new File(path); File[] listOfFiles = folder.listFiles(); DefaultListModel listModel = new DefaultListModel(); int count = 0; for (int i = 0; i < listOfFiles.length; i++) { String name = listOfFiles[i].toString(); if (name.endsWith("jpg")) { ImageIcon ii = new ImageIcon(ImageIO.read(listOfFiles[i])); listModel.add(count++, ii);// w ww. ja va 2 s . co m } } JList lsm = new JList(listModel); lsm.setVisibleRowCount(1); frame.add(new JScrollPane(lsm)); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) throws IOException { BufferedImage origin = ImageIO.read(new URL("http://www.java2s.com/style/download.png")); File dest = new File("c:/Java_Dev/out.png"); ImageIO.write(resize(200, 200, origin), "PNG", dest); }
From source file:Main.java
public static void main(String[] args) { final JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton loadButton = new JButton("Display Image"); loadButton.addActionListener(ev -> { JFileChooser fc = new JFileChooser(System.getProperty("user.home")); fc.addChoosableFileFilter(//www.j a v a2s. co m new FileNameExtensionFilter("Image files", new String[] { "png", "jpg", "jpeg", "gif" })); if (fc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { try { Image image = ImageIO.read(fc.getSelectedFile()); if (image != null) { JPanel panel = new JPanel(new BorderLayout(10, 10)); panel.add(new JLabel(fc.getSelectedFile().toString()), BorderLayout.NORTH); panel.add(new JLabel(new ImageIcon(image))); JOptionPane.showMessageDialog(frame, panel); } } catch (Exception ex) { ex.printStackTrace(); } } }); frame.add(loadButton); frame.pack(); frame.setLocationByPlatform(true); frame.setVisible(true); }
From source file:akori.Impact.java
static public void main(String[] args) throws IOException { String PATH = "E:\\Trabajos\\AKORI\\datosmatrizgino\\"; String PATHIMG = "E:\\NetBeansProjects\\AKORI\\Proccess_1\\ImagesPages\\"; for (int i = 1; i <= 32; ++i) { for (int k = 1; k <= 15; ++k) { System.out.println("Matrix " + i + "-" + k); BufferedImage img = null; try { img = ImageIO.read(new File(PATHIMG + i + ".png")); } catch (IOException ex) { ex.getStackTrace();/*from ww w . j a v a 2 s .co m*/ } int ymax = img.getHeight(); int xmax = img.getWidth(); double[][] imagen = new double[ymax][xmax]; BufferedReader in = null; try { in = new BufferedReader(new FileReader(PATH + i + "-" + k + ".txt")); } catch (FileNotFoundException ex) { ex.getStackTrace(); } String linea; ArrayList<String> lista = new ArrayList<String>(); HashMap<String, String> lista1 = new HashMap<String, String>(); try { for (int j = 0; (linea = in.readLine()) != null; ++j) { String[] datos = linea.split(","); int x = (int) Double.parseDouble(datos[1]); int y = (int) Double.parseDouble(datos[2]); if (x >= xmax || y >= ymax || x <= 0 || y <= 0) { continue; } lista.add(x + "," + y); } } catch (Exception ex) { ex.getStackTrace(); } try { in.close(); } catch (IOException ex) { ex.getStackTrace(); } Iterator iter = lista.iterator(); int[][] matrix = new int[lista.size()][2]; for (int j = 0; iter.hasNext(); ++j) { String xy = (String) iter.next(); String[] datos = xy.split(","); matrix[j][0] = Integer.parseInt(datos[0]); matrix[j][1] = Integer.parseInt(datos[1]); } for (int j = 0; j < matrix.length; ++j) { int std = 50; int x = matrix[j][0]; int y = matrix[j][1]; imagen[y][x] += 1; double aux; normalMatrix(imagen, y, x, std); } FileWriter fw = new FileWriter(PATH + "Matrix" + i + "-" + k + ".txt"); BufferedWriter bw = new BufferedWriter(fw); for (int j = 0; j < imagen.length; ++j) { for (int t = 0; t < imagen[j].length; ++t) { if (t + 1 == imagen[j].length) bw.write(imagen[j][t] + ""); else bw.write(imagen[j][t] + ","); } bw.write("\n"); } bw.close(); } } }
From source file:Main.java
public static void main(String[] args) throws Exception { JFrame Main = new JFrame("Gradient Mask"); JLabel imageLayer = new JLabel(); JLabel maskLayer = new JLabel(); BufferedImage image = ImageIO.read(new URL("http://www.java2s.com/style/download.png")); BufferedImage gradientMask = new GradientImage(image.getWidth(), image.getHeight(), new Color[] { new Color(255, 255, 255, 125), Color.BLACK }, GradientImage.RADIAL_FROM_CENTER) .getImage();//from ww w. j a va 2s . co m Main.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Main.setBounds(100, 50, image.getWidth(), image.getHeight()); imageLayer.setBounds(0, 0, Main.getWidth(), Main.getHeight()); maskLayer.setBounds(0, 0, Main.getWidth(), Main.getHeight()); imageLayer.setIcon(new ImageIcon((Image) image)); maskLayer.setIcon(new ImageIcon((Image) gradientMask)); Main.getContentPane().add(imageLayer); imageLayer.add(maskLayer); Main.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 trans = getTransparentImage(ImageIO.read(url), Color.BLACK); Runnable r = new Runnable() { @Override/*from w ww . ja va 2 s. com*/ public void run() { JLabel gui = new JLabel(new ImageIcon(trans)); JOptionPane.showMessageDialog(null, gui); } }; SwingUtilities.invokeLater(r); }
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 bi = ImageIO.read(url); SwingUtilities.invokeLater(new Runnable() { @Override//from w ww .j a v a 2s .c o m public void run() { int strokeWidth = 12; int pad = 50; Shape shape = new Rectangle(pad, pad, bi.getWidth() - (2 * pad), bi.getHeight() - (2 * pad)); Image i = getStrokedImage(bi, shape, strokeWidth); JOptionPane.showMessageDialog(null, new JLabel(new ImageIcon(i))); } }); }
From source file:Main.java
public static void main(String[] args) throws AWTException { Runnable r = new Runnable() { @Override/* w ww.j a v a 2 s.co m*/ public void run() { try { URL url = new URL("http://www.java2s.com/style/download.png"); BufferedImage bi = ImageIO.read(url); JPanel gui = new JPanel(new GridLayout(1, 2, 2, 2)); gui.add(new JLabel(new ImageIcon(bi))); gui.add(new JLabel(new ImageIcon(getFlippedImage(bi)))); JOptionPane.showMessageDialog(null, gui); } catch (Exception e) { e.printStackTrace(); } } }; SwingUtilities.invokeLater(r); }
From source file:com.rest.samples.getImagePrintJPanel.java
public static void main(String[] args) { // TODO code application logic here String url = "https://api.adorable.io/avatars/eyes5"; try {/*from w w w .j av a2s.co m*/ HttpClient hc = HttpClientBuilder.create().build(); HttpGet getMethod = new HttpGet(url); getMethod.addHeader("accept", "application/png"); HttpResponse res = hc.execute(getMethod); if (res.getStatusLine().getStatusCode() != 200) { throw new RuntimeException("Failed : HTTP eror code: " + res.getStatusLine().getStatusCode()); } InputStream is = res.getEntity().getContent(); Image image = ImageIO.read(is); JFrame frame = new JFrame(); JLabel label = new JLabel(new ImageIcon(image)); frame.getContentPane().add(label, BorderLayout.CENTER); frame.pack(); frame.setVisible(true); } catch (IOException ex) { Logger.getLogger(SamplesUseHttpclient.class.getName()).log(Level.SEVERE, null, ex); } }