List of usage examples for java.awt.image BufferedImage BufferedImage
public BufferedImage(int width, int height, int imageType)
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);/* w w w. j a va 2s. co m*/ 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:MakeFades.java
public static void main(String[] args) throws IOException, NumberFormatException { // Create from and to colors based on those arguments Color from = Color.RED; // transparent Color to = Color.BLACK; // opaque // Loop through the sizes and directions, and create an image for each for (int s = 0; s < sizes.length; s++) { for (int d = 0; d < directions.length; d++) { // This is the size of the image int size = sizes[s]; // Create a GradientPaint for this direction and size Paint paint = new GradientPaint(directions[d][0] * size, directions[d][1] * size, from, directions[d][2] * size, directions[d][3] * size, to); // Start with a blank image that supports transparency BufferedImage image = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB); // Now use fill the image with our color gradient Graphics2D g = image.createGraphics(); g.setPaint(paint);/*w w w. ja v a2s. c o m*/ g.fillRect(0, 0, size, size); // This is the name of the file we'll write the image to File file = new File("fade-to-" + sizeNames[s] + "-" + directionNames[d] + ".png"); // Save the image in PNG format using the javax.imageio API javax.imageio.ImageIO.write(image, "png", file); // Show the user our progress by printing the filename System.out.println(file); } } }
From source file:com.tonygalati.sprites.SpriteGenerator.java
public static void main(String[] args) throws IOException { // if (args.length != 3) // {/*from w w w .j a va 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
static BufferedImage average(BufferedImage[] images) { BufferedImage average = new BufferedImage(images[0].getWidth(), images[0].getHeight(), BufferedImage.TYPE_BYTE_GRAY); WritableRaster raster = average.getRaster().createCompatibleWritableRaster(); for (int k = 0; k < images[0].getHeight(); ++k) { for (int j = 0; j < images[0].getWidth(); ++j) { float sum = 0.0f; for (int i = 0; i < images.length; ++i) { sum = sum + images[i].getRaster().getSample(j, k, 0); }//from www. j av a 2s . c o m raster.setSample(j, k, 0, Math.round(sum / images.length)); } } average.setData(raster); return average; }
From source file:Main.java
private static BufferedImage prepareImage(BufferedImage image, int shadowSize) { BufferedImage subject = new BufferedImage(image.getWidth() + shadowSize * 2, image.getHeight() + shadowSize * 2, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = subject.createGraphics(); g2.drawImage(image, null, shadowSize, shadowSize); g2.dispose();//from w ww . j a v a 2 s . c o m return subject; }
From source file:Main.java
static BufferedImage enlarge(BufferedImage image, int n) { int w = image.getWidth() / n; int h = image.getHeight() / n; BufferedImage shrunkImage = new BufferedImage(w, h, image.getType()); for (int y = 0; y < h; ++y) for (int x = 0; x < w; ++x) shrunkImage.setRGB(x, y, image.getRGB(x * n, y * n)); return shrunkImage; }
From source file:Util.java
/** * Converts an Image to a BufferedImage/*from w w w .ja va 2s. co m*/ */ public static BufferedImage convertToBufferedImg(Image im) { BufferedImage bi = new BufferedImage(im.getWidth(null), im.getHeight(null), BufferedImage.TYPE_INT_ARGB); Graphics bg = bi.getGraphics(); bg.drawImage(im, 0, 0, null); bg.dispose(); return bi; }
From source file:Main.java
public static BufferedImage getTransparentImage(BufferedImage image, Color transparent) { BufferedImage img = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D g = img.createGraphics(); for (int x = 0; x < img.getWidth(); x++) { for (int y = 0; y < img.getHeight(); y++) { if (image.getRGB(x, y) != transparent.getRGB()) { img.setRGB(x, y, image.getRGB(x, y)); }/*from ww w . ja va 2s. c om*/ } } g.dispose(); return img; }
From source file:Main.java
private static BufferedImage map(int sizeX, int sizeY) { final BufferedImage res = new BufferedImage(sizeX, sizeY, BufferedImage.TYPE_INT_RGB); for (int x = 0; x < sizeX; x++) { for (int y = 0; y < sizeY; y++) { res.setRGB(x, y, Color.WHITE.getRGB()); }/* w w w .j a v a2 s .c o m*/ } return res; }
From source file:Main.java
public static TexturePaint createCheckerTexture(int cs, Color color) { int size = cs * cs; BufferedImage img = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = img.createGraphics(); g2.setPaint(color);// w ww . j av a2 s.c o m g2.fillRect(0, 0, size, size); for (int i = 0; i * cs < size; i++) { for (int j = 0; j * cs < size; j++) { if ((i + j) % 2 == 0) { g2.fillRect(i * cs, j * cs, cs, cs); } } } g2.dispose(); return new TexturePaint(img, new Rectangle(0, 0, size, size)); }