Skip to content

Instantly share code, notes, and snippets.

@fdb
Created July 5, 2012 21:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fdb/3056454 to your computer and use it in GitHub Desktop.
Save fdb/3056454 to your computer and use it in GitHub Desktop.
Writing a bitmap image in Clojure
; This example shows how to write a bitmap image using Clojure
; Import the necessary classes.
(import 'java.awt.image.BufferedImage 'javax.imageio.ImageIO 'java.awt.Color 'java.io.File)
; Create a new image with a 100x100 size. The image is going to have four color channels.
(def img (BufferedImage. 100 100 BufferedImage/TYPE_INT_ARGB))
; Draw on the image by getting the graphics object and invoking methods on it.
(doto (.getGraphics img)
(.setColor Color/BLUE)
(.fillRect 0 0 100 100))
; Use ImageIO to write out the image to a PNG file.
(ImageIO/write img "png" (File. "test.png"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment