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 Exception { URL urlFG = new URL("http://www.java2s.com/style/download.png"); URL urlBG = new URL("http://www.java2s.com/style/download.png"); final BufferedImage biFG = ImageIO.read(urlFG); final BufferedImage biBG = ImageIO.read(urlBG); SwingUtilities.invokeLater(new Runnable() { @Override//from w w w . j ava 2s.c o m public void run() { draw(biBG, biFG); } }); }
From source file:akori.AKORI.java
public static void main(String[] args) throws IOException, InterruptedException { System.out.println("esto es AKORI"); URL = "http://www.mbauchile.cl"; PATH = "E:\\NetBeansProjects\\AKORI\\"; NAME = "mbauchile.png"; // Extrar DOM tree Document doc = Jsoup.connect(URL).timeout(0).get(); // The Firefox driver supports javascript WebDriver driver = new FirefoxDriver(); driver.manage().window().maximize(); System.out.println(driver.manage().window().getSize().toString()); System.out.println(driver.manage().window().getPosition().toString()); int xmax = driver.manage().window().getSize().width; int ymax = driver.manage().window().getSize().height; // Go to the URL page driver.get(URL);/*from w ww . java2 s . c om*/ File screen = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(screen, new File(PATH + NAME)); BufferedImage img = ImageIO.read(new File(PATH + NAME)); //Graphics2D graph = img.createGraphics(); BufferedImage img1 = new BufferedImage(xmax, ymax, BufferedImage.TYPE_INT_ARGB); Graphics2D graph1 = img.createGraphics(); double[][] matrix = new double[ymax][xmax]; BufferedReader in = new BufferedReader(new FileReader("et.txt")); String linea; double max = 0; graph1.drawImage(img, 0, 0, null); HashMap<String, Integer> lista = new HashMap<String, Integer>(); int count = 0; for (int i = 0; (linea = in.readLine()) != null && i < 10000; ++i) { String[] datos = linea.split(","); int x = (int) Double.parseDouble(datos[0]); int y = (int) Double.parseDouble(datos[2]); long time = Double.valueOf(datos[4]).longValue(); if (x >= xmax || y >= ymax) continue; if (time < 691215) continue; if (time > 705648) break; if (lista.containsKey(x + "," + y)) lista.put(x + "," + y, lista.get(x + "," + y) + 1); else lista.put(x + "," + y, 1); ++count; } System.out.println(count); in.close(); Iterator iter = lista.entrySet().iterator(); Map.Entry e; for (String key : lista.keySet()) { Integer i = lista.get(key); if (max < i) max = i; } System.out.println(max); max = 0; while (iter.hasNext()) { e = (Map.Entry) iter.next(); String xy = (String) e.getKey(); String[] datos = xy.split(","); int x = Integer.parseInt(datos[0]); int y = Integer.parseInt(datos[1]); matrix[y][x] += (int) e.getValue(); double aux; if ((aux = normalMatrix(matrix, y, x, ((int) e.getValue()) * 4)) > max) { max = aux; } //normalMatrix(matrix,x,y,20); if (matrix[y][x] > max) max = matrix[y][x]; } int A, R, G, B, n; for (int i = 0; i < xmax; ++i) { for (int j = 0; j < ymax; ++j) { if (matrix[j][i] != 0) { n = (int) Math.round(matrix[j][i] * 100 / max); R = Math.round((255 * n) / 100); G = Math.round((255 * (100 - n)) / 100); B = 0; A = Math.round((255 * n) / 100); ; if (R > 255) R = 255; if (R < 0) R = 0; if (G > 255) G = 255; if (G < 0) G = 0; if (R < 50) A = 0; graph1.setColor(new Color(R, G, B, A)); graph1.fillOval(i, j, 1, 1); } } } //graph1.dispose(); ImageIO.write(img, "png", new File("example.png")); System.out.println(max); graph1.setColor(Color.RED); // Extraer elementos Elements e1 = doc.body().getAllElements(); int i = 1; ArrayList<String> tags = new ArrayList<String>(); for (Element temp : e1) { if (tags.indexOf(temp.tagName()) == -1) { tags.add(temp.tagName()); List<WebElement> query = driver.findElements(By.tagName(temp.tagName())); for (WebElement temp1 : query) { Point po = temp1.getLocation(); Dimension d = temp1.getSize(); if (d.width <= 0 || d.height <= 0 || po.x < 0 || po.y < 0) continue; System.out.println(i + " " + temp.nodeName()); System.out.println(" x: " + po.x + " y: " + po.y); System.out.println(" width: " + d.width + " height: " + d.height); graph1.draw(new Rectangle(po.x, po.y, d.width, d.height)); ++i; } } } graph1.dispose(); ImageIO.write(img, "png", new File(PATH + NAME)); driver.quit(); }
From source file:ai.emot.demo.EmotAIDemo.java
public static void main(String[] args) throws IOException, InterruptedException { if (args.length != 2) { printUsage();// w w w .j a v a2 s .c o m System.exit(0); } String emotAIAPIBaseUrl = args[0]; String accessToken = args[1]; PathMatchingResourcePatternResolver fileResolver = new PathMatchingResourcePatternResolver( EmotAIDemo.class.getClassLoader()); Resource[] resources = fileResolver.getResources("images"); File dir = resources[0].getFile(); File imagesDir = new File(dir, "/face/cropped"); EmotAI emotAI = new EmotAITemplate(emotAIAPIBaseUrl, accessToken); // Create a display for the images ImageDisplay<Long> imageDisplay = new ImageDisplay<Long>(250, 250); for (File imageFile : imagesDir.listFiles(new JpegFileFilter())) { // Read each image BufferedImage image = ImageIO.read(imageFile); // Get the emotion profile for each image EmotionProfile emotionProfile = emotAI.emotionOperations().getFaceImageEmotionProfile(image); // Output emotion, and display image System.out.println(imageFile.getName() + " : " + emotionProfile); imageDisplay.onFrameUpdate(new SerializableBufferedImageAdapter(image), 1l); // Sleep for 1 second Thread.sleep(1000); } System.exit(1); }
From source file:edu.harvard.mcz.imagecapture.BarcodeReadTest.java
/** * Launches the application, checking one image file for a barcode. * /*from ww w . j ava2 s. c o m*/ * @param args takes filename to read as the first argument. */ public static void main(String[] args) { if (args.length == 0) { System.out.println("java BarcodeReadTest filename"); } else { String filename = args[0]; File file = new File(filename); try { log.debug(file.getCanonicalPath()); BufferedImage image = ImageIO.read(file); System.out.println(checkForBarcode(image)); } catch (IOException e) { e.printStackTrace(); } } }
From source file:ImageLabel.java
public static void main(String args[]) { JFrame frame = new JFrame("Image Label"); BufferedImage img = null;//from w ww . j a v a 2 s.c o m try { String imageFileName = "painting.gif"; img = ImageIO.read(new File(imageFileName)); } catch (IOException e) { } frame.add("Center", new ImageLabel(img, "Java 2D Graphics!")); frame.pack(); frame.setVisible(true); }
From source file:com.tonygalati.sprites.SpriteGenerator.java
public static void main(String[] args) throws IOException { // if (args.length != 3) // {/* w w w.ja v a 2s.c o m*/ // System.out.print("Usage: com.tonygalati.sprites.SpriteGenerator {path to images} {margin between images in px} {output file}\n"); // System.out.print("Note: The max height should only be around 32,767px due to Microsoft GDI using a 16bit signed integer to store dimensions\n"); // System.out.print("going beyond this dimension is possible with this tool but the generated sprite image will not work correctly with\n"); // System.out.print("most browsers.\n\n"); // return; // } // Integer margin = Integer.parseInt(args[1]); Integer margin = Integer.parseInt("1"); String spriteFile = "icons-" + RandomStringUtils.randomAlphanumeric(10) + ".png"; SpriteCSSGenerator cssGenerator = new SpriteCSSGenerator(); ClassLoader classLoader = SpriteGenerator.class.getClassLoader(); URL folderPath = classLoader.getResource(NAIC_SMALL_ICON); if (folderPath != null) { File imageFolder = new File(folderPath.getPath()); // Read images ArrayList<BufferedImage> imageList = new ArrayList<BufferedImage>(); Integer yCoordinate = null; for (File f : imageFolder.listFiles()) { if (f.isFile()) { String fileName = f.getName(); String ext = fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length()); if (ext.equals("png")) { System.out.println("adding file " + fileName); BufferedImage image = ImageIO.read(f); imageList.add(image); if (yCoordinate == null) { yCoordinate = 0; } else { yCoordinate += (image.getHeight() + margin); } // add to cssGenerator cssGenerator.addSpriteCSS(fileName.substring(0, fileName.indexOf(".")), 0, yCoordinate); } } } // Find max width and total height int maxWidth = 0; int totalHeight = 0; for (BufferedImage image : imageList) { totalHeight += image.getHeight() + margin; if (image.getWidth() > maxWidth) maxWidth = image.getWidth(); } System.out.format("Number of images: %s, total height: %spx, width: %spx%n", imageList.size(), totalHeight, maxWidth); // Create the actual sprite BufferedImage sprite = new BufferedImage(maxWidth, totalHeight, BufferedImage.TYPE_INT_ARGB); int currentY = 0; Graphics g = sprite.getGraphics(); for (BufferedImage image : imageList) { g.drawImage(image, 0, currentY, null); currentY += image.getHeight() + margin; } System.out.format("Writing sprite: %s%n", spriteFile); ImageIO.write(sprite, "png", new File(spriteFile)); File cssFile = cssGenerator.getFile(spriteFile); System.out.println(cssFile.getAbsolutePath() + " created"); } else { System.err.println("Could not find folder: " + NAIC_SMALL_ICON); } }
From source file:Main.java
public static void main(String[] args) throws Exception { anImage = new ImageIcon(ImageIO.read(new URL("http://www.java2s.com/style/download.png"))); new Main().initComponents(); }
From source file:net.forkwait.imageautomator.ImageAutomator.java
public static void main(String[] args) throws IOException { String inputImage = ""; Options options = new Options(); options.addOption("o", true, "output file name (e.g. thumb.jpg), default thumbnail.filename.ext"); options.addOption("q", true, "jpeg quality (e.g. 0.9, max 1.0), default 0.97"); options.addOption("s", true, "output max side length in px (e.g. 800), default 1200"); options.addOption("w", true, "watermark image file"); options.addOption("wt", true, "watermark transparency (e.g. 0.5, max 1.0), default 1.0"); options.addOption("wp", true, "watermark position (e.g. 0.9, max 1.0), default BOTTOM_RIGHT"); /*/* www . j av a 2 s . c o m*/ TOP_LEFT TOP_CENTER TOP_RIGHT CENTER_LEFT CENTER CENTER_RIGHT BOTTOM_LEFT BOTTOM_CENTER BOTTOM_RIGHT */ CommandLineParser parser = new BasicParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); if (cmd.getArgs().length < 1) { throw new ParseException("Too few arguments"); } else if (cmd.getArgs().length > 1) { throw new ParseException("Too many arguments"); } inputImage = cmd.getArgs()[0]; } catch (ParseException e) { showHelp(options, e.getLocalizedMessage()); System.exit(-1); } Thumbnails.Builder<File> st = Thumbnails.of(inputImage); if (cmd.hasOption("q")) { st.outputQuality(Double.parseDouble(cmd.getOptionValue("q"))); } else { st.outputQuality(0.97f); } if (cmd.hasOption("s")) { st.size(Integer.parseInt(cmd.getOptionValue("s")), Integer.parseInt(cmd.getOptionValue("s"))); } else { st.size(1200, 1200); } if (cmd.hasOption("w")) { Positions position = Positions.BOTTOM_RIGHT; float trans = 0.5f; if (cmd.hasOption("wp")) { position = Positions.valueOf(cmd.getOptionValue("wp")); } if (cmd.hasOption("wt")) { trans = Float.parseFloat(cmd.getOptionValue("wt")); } st.watermark(position, ImageIO.read(new File(cmd.getOptionValue("w"))), trans); } if (cmd.hasOption("o")) { st.toFile(new File(cmd.getOptionValue("o"))); } else { st.toFiles(Rename.PREFIX_DOT_THUMBNAIL); } //.outputFormat("jpg") System.exit(0); }
From source file:de.mycrobase.jcloudapp.Main.java
public static void main(String[] args) throws Exception { try {// w w w . j av a2 s . c o m // borrowed from https://github.com/cmur2/gloudapp ImageNormal = ImageIO.read(Main.class.getResourceAsStream("gloudapp.png")); ImageWorking = ImageIO.read(Main.class.getResourceAsStream("gloudapp_working.png")); IconNormal = new ImageIcon(ImageNormal.getScaledInstance(64, 64, Image.SCALE_SMOOTH)); IconLarge = new ImageIcon(ImageNormal); } catch (IOException ex) { showErrorDialog("Could not load images!\n" + ex); System.exit(1); } URI serviceUrl = URI.create("http://my.cl.ly:80/"); File storage = getStorageFile(); if (storage.exists() && storage.isFile()) { Yaml yaml = new Yaml(); try { Map<String, String> m = (Map<String, String>) yaml.load(new FileInputStream(storage)); // avoid NPE by implicitly assuming the presence of a service URL if (m.containsKey("service_url")) { serviceUrl = URI.create(m.get("service_url")); } } catch (IOException ex) { showErrorDialog("Loading settings from .cloudapp-cli failed: " + ex); System.exit(1); } } Main app = new Main(serviceUrl); app.login(args); app.run(); }
From source file:de.bamamoto.mactools.png2icns.Scaler.java
public static void main(String[] args) { Options options = new Options(); options.addOption("i", "input-filename", true, "Filename ofthe image containing the icon. The image should be a square with at least 1024x124 pixel in PNG format."); options.addOption("o", "iconset-foldername", true, "Name of the folder where the iconset will be stored. The extension .iconset will be added automatically."); String folderName;/*ww w . j a v a 2 s . c om*/ CommandLineParser parser = new DefaultParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); if (cmd.hasOption("i")) { if (new File(cmd.getOptionValue("i")).isFile()) { if (cmd.hasOption("o")) { folderName = cmd.getOptionValue("o"); } else { folderName = "/tmp/noname.iconset"; } if (!folderName.endsWith(".iconset")) { folderName = folderName + ".iconset"; } new File(folderName).mkdirs(); BufferedImage source = ImageIO.read(new File(cmd.getOptionValue("i"))); BufferedImage resized = resize(source, 1024, 1024); save(resized, folderName + "/icon_512x512@2x.png"); resized = resize(source, 512, 512); save(resized, folderName + "/icon_512x512.png"); save(resized, folderName + "/icon_256x256@2x.png"); resized = resize(source, 256, 256); save(resized, folderName + "/icon_256x256.png"); save(resized, folderName + "/icon_128x128@2x.png"); resized = resize(source, 128, 128); save(resized, folderName + "/icon_128x128.png"); resized = resize(source, 64, 64); save(resized, folderName + "/icon_32x32@2x.png"); resized = resize(source, 32, 32); save(resized, folderName + "/icon_32x32.png"); save(resized, folderName + "/icon_16x16@2x.png"); resized = resize(source, 16, 16); save(resized, folderName + "/icon_16x16.png"); Scaler.runProcess(new String[] { "/usr/bin/iconutil", "-c", "icns", folderName }); } } } catch (IOException e) { System.out.println("Error reading image: " + cmd.getOptionValue("i")); e.printStackTrace(); } catch (ParseException ex) { Logger.getLogger(Scaler.class.getName()).log(Level.SEVERE, null, ex); } }