List of usage examples for javax.imageio ImageIO read
public static BufferedImage read(ImageInputStream stream) throws IOException
From source file:Main.java
public MyPanel() throws Exception { setLayout(new FlowLayout()); int size = 100; URL url = new URL("http://www.java2s.com/style/download.png"); BufferedImage bi = ImageIO.read(url); Image left = createImage(size, Color.YELLOW); Image merged = merge(left, bi); add(new JLabel(new ImageIcon(merged))); }
From source file:exemplos.PegandoPixelsSemJAI.java
public void pegaPixel() throws IOException { File f = new File("D:\\ProjetosNetBeans\\PDI\\src\\imagens\\ebola.png"); //seleciona o arquivo BufferedImage image = ImageIO.read(f); //le o arquivo System.out.println("Dimenses: " + image.getWidth() + "x" + image.getHeight() + "pixels"); //exibe suas dimenses Raster raster = image.getRaster(); //pega os valores dos pixels double pixel[] = new double[3]; //cria um array com 3 posies int brancos = 0; //cria uma varivel para contar os pixels brancos for (int h = 0; h < image.getHeight(); h++) for (int w = 0; w < image.getWidth(); w++) { raster.getPixel(w, h, pixel); if ((pixel[0] == 255) && (pixel[1] == 255) && (pixel[2] == 255))//confirma se o RGB igual a 255, ou seja, branco brancos++;/*from w ww. ja v a 2 s. c o m*/ } }
From source file:com.github.carlomicieli.nerdmovies.utility.ImageUtils.java
private static BufferedImage convertToImage(MultipartFile file) throws IOException { InputStream in = new ByteArrayInputStream(file.getBytes()); return ImageIO.read(in); }
From source file:Main.java
/** * Set the icon if a window.// w ww . j a va2s .co m * * @param window Window to change the icon of. * @param imageInputStream Input stream of the image. */ public static void setWindowIcon(Window window, InputStream imageInputStream) { try { // Load the image and set the window icon window.setIconImage(ImageIO.read(imageInputStream)); } catch (IOException | NullPointerException e) { System.out.println("Failed to set window icon."); } }
From source file:Main.java
/** * Set the icon if a dialog.//from w w w .ja va2s . c o m * * @param dialog Dialog to change the icon of. * @param imageInputStream Input stream of the image. */ public static void setDialogIcon(JDialog dialog, InputStream imageInputStream) { try { // Load the image and set the window icon dialog.setIconImage(ImageIO.read(imageInputStream)); } catch (IOException | NullPointerException e) { System.out.println("Failed to set window icon."); } }
From source file:ml.hsv.java
public static hsv[][] img2RGB2HSV(String ip) throws IOException { BufferedImage image;//from w w w .j a v a 2 s.c o m int width, height; File input = new File(ip); image = ImageIO.read(input); width = image.getWidth(); height = image.getHeight(); hsv hsvImage[][] = new hsv[height][width]; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { Color c = new Color(image.getRGB(j, i)); hsvImage[i][j] = new hsv(c.getRed(), c.getGreen(), c.getBlue()); } } HSV2File(hsvImage, width, height); return hsvImage; }
From source file:net.sf.nmedit.jtheme.JTCursor.java
private static Cursor createCursor(int id) { Toolkit tk = Toolkit.getDefaultToolkit(); URL res = getResource(id);/* ww w . j a v a2 s .c o m*/ if (res == null) { Log log = LogFactory.getLog(JTCursor.class); if (log.isWarnEnabled()) { log.warn("Could not find cursor: id=" + id + ", url=" + res); } return Cursor.getDefaultCursor(); } Image img; try { img = ImageIO.read(res); } catch (IOException e) { Log log = LogFactory.getLog(JTCursor.class); if (log.isWarnEnabled()) { log.warn("Could not find cursor: id=" + id + ", url=" + res, e); } return Cursor.getDefaultCursor(); } return tk.createCustomCursor(img, new Point(4, 16), names[id]); }
From source file:com.quartercode.disconnected.util.LocationGenerator.java
/** * Generates the given amount of locations on an earth map, ignoring the given ignore locations. * /* ww w .j a va 2 s. c om*/ * @param amount The amount of locations to generate. * @return The generated locations. * @throws RuntimeException The map image can't be read. */ public static List<Location> generateLocations(int amount, List<Location> ignore) { Validate.isTrue(amount > 0, "Generation amount must be > 0: ", amount); if (map == null) { try { map = ImageIO.read(LocationGenerator.class.getResource("/data/map.png")); } catch (IOException e) { throw new RuntimeException("Can't read map data image", e); } } if (ignore == null) { ignore = new ArrayList<Location>(); } int width = map.getWidth(); int height = map.getHeight(); List<Location> result = new ArrayList<Location>(); RandomPool random = new RandomPool(100); int blackRGB = Color.BLACK.getRGB(); while (result.size() < amount) { int x = random.nextInt(width); int y = random.nextInt(height); if (map.getRGB(x, y) == blackRGB) { Location location = new Location((float) x / (float) width, (float) y / (float) height); if (!ignore.contains(location) && !result.contains(location)) { result.add(location); } } } return result; }
From source file:ScrollPaneWatermark.java
public void setForegroundBadge(URL url) throws IOException { fgimage = ImageIO.read(url); }
From source file:de.mprengemann.intellij.plugin.androidicons.images.ImageUtils.java
public static void updateImage(JLabel imageContainer, File imageFile) { if (!imageFile.exists()) { return;/*from www . j av a2s . c o m*/ } BufferedImage img = null; try { img = ImageIO.read(imageFile); } catch (IOException e) { e.printStackTrace(); } if (img == null) { return; } int imageWidth = img.getWidth(); int imageHeight = img.getHeight(); int imageViewWidth = imageContainer.getWidth(); int imageViewHeight = imageContainer.getHeight(); double factor = getScaleFactorToFit(new Dimension(imageWidth, imageHeight), new Dimension(imageViewWidth, imageViewHeight)); factor = Math.min(factor, 1f); imageWidth = (int) (factor * imageWidth); imageHeight = (int) (factor * imageHeight); if (imageWidth <= 0 || imageHeight <= 0 || imageViewWidth <= 0 || imageViewHeight <= 0) { return; } BufferedImage tmp = UIUtil.createImage(imageViewWidth, imageViewHeight, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = tmp.createGraphics(); g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); int x = (imageViewWidth - imageWidth) / 2; int y = (imageViewHeight - imageHeight) / 2; g2.drawImage(img, x, y, imageWidth, imageHeight, null); g2.dispose(); imageContainer.setIcon(new ImageIcon(tmp)); }