Skip to content

Instantly share code, notes, and snippets.

@AndrewReitz
Created February 15, 2016 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save AndrewReitz/ed09237e996c9c0099bf to your computer and use it in GitHub Desktop.
Save AndrewReitz/ed09237e996c9c0099bf to your computer and use it in GitHub Desktop.
Write Image in Groovy/Java
import javax.imageio.ImageIO
import java.awt.image.BufferedImage
def image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB)
for (x in 0..99) {
for (y in 0..99) {
int color = (x + y) % 2 == 0 ? 0x000000 : 0xffffff
image.setRGB(x, y, color)
}
}
def file = new File('test.png')
ImageIO.write(image, 'png', file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment