Created
July 5, 2012 21:12
-
-
Save fdb/3056454 to your computer and use it in GitHub Desktop.
Writing a bitmap image in Clojure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; 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