Skip to content

Instantly share code, notes, and snippets.

@PauloMigAlmeida
Created June 18, 2014 15:01
Show Gist options
  • Save PauloMigAlmeida/7e0658e5e6a39071090b to your computer and use it in GitHub Desktop.
Save PauloMigAlmeida/7e0658e5e6a39071090b to your computer and use it in GitHub Desktop.
Class used to create a bunch of images with random colors for later use
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.color.ColorSpace;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Random;
/**
* Class used to create a bunch of images with random color for later use
* User: paulo.rodenas
* Date: 6/18/14
* Time: 11:37 AM
*/
public class GenerateImage {
public static void main(String[] args) throws IOException {
String path = "/Users/paulo.rodenas/Desktop/montageTestFiles/baseImages";
Random random = new Random();
int r=0, g=0, b=0;
for(int i=0; i < 400; i++){
r = random.nextInt(255);
g = random.nextInt(255);
b = random.nextInt(255);
BufferedImage bufferedImage = new BufferedImage(640,640, ColorSpace.TYPE_RGB);
Graphics2D graphics = bufferedImage.createGraphics();
graphics.setPaint ( new Color ( r, g, b ) );
graphics.fillRect ( 0, 0, bufferedImage.getWidth(), bufferedImage.getHeight() );
ImageIO.write(bufferedImage,"png",new File(path + String.format("/%d.png",i)));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment