Skip to content

Instantly share code, notes, and snippets.

@Serabe
Created October 18, 2010 19:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Serabe/632849 to your computer and use it in GitHub Desktop.
Save Serabe/632849 to your computer and use it in GitHub Desktop.
user> (.setComposite g-clj (src-out))
; Evaluation aborted.
user> (.setComposite g-clj (src-out 1))
; Evaluation aborted.
user> (def a (src-out))
#'user/a
user> (.setComposite g-clj a)
nil
Can't embed object in code, maybe print-dup not defined: java.awt.AlphaComposite@b0800007
[Thrown class java.lang.RuntimeException]
(defmacro with-composite
"Sets the composite of the dest to comp, and restores original composite value after executing the body.
Body executes inside a doto bounded to a Graphics2D object."
[img comp & body]
(let [eval-comp comp]
`(let [ni# (clone-image ~img)
g2# ^Graphics2D (.. (:image ni#) getGraphics)
orig-comp# (.. g2# getComposite)]
(doto g2#
(.setComposite ~eval-comp)
~@body
(.setComposite orig-comp#))
ni#)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment