comparison org/test-creature.org @ 114:9d0fe7f54e14

merged image viewing code to cortex.util
author Robert McIntyre <rlm@mit.edu>
date Thu, 19 Jan 2012 22:19:24 -0700
parents 128fa71ee188
children 247860e25536
comparison
equal deleted inserted replaced
113:a980462ebe76 114:9d0fe7f54e14
64 (import javax.swing.JFrame) 64 (import javax.swing.JFrame)
65 (import java.awt.Dimension) 65 (import java.awt.Dimension)
66 (import com.aurellem.capture.RatchetTimer) 66 (import com.aurellem.capture.RatchetTimer)
67 (declare joint-create) 67 (declare joint-create)
68 (use 'clojure.contrib.def) 68 (use 'clojure.contrib.def)
69
70 (defn view-image
71 "Initailizes a JPanel on which you may draw a BufferedImage.
72 Returns a function that accepts a BufferedImage and draws it to the
73 JPanel."
74 []
75 (let [image
76 (atom
77 (BufferedImage. 1 1 BufferedImage/TYPE_4BYTE_ABGR))
78 panel
79 (proxy [JPanel] []
80 (paint
81 [graphics]
82 (proxy-super paintComponent graphics)
83 (.drawImage graphics @image 0 0 nil)))
84 frame (JFrame. "Display Image")]
85 (SwingUtilities/invokeLater
86 (fn []
87 (doto frame
88 (-> (.getContentPane) (.add panel))
89 (.pack)
90 (.setLocationRelativeTo nil)
91 (.setResizable true)
92 (.setVisible true))))
93 (fn [#^BufferedImage i]
94 (reset! image i)
95 (.setSize frame (+ 8 (.getWidth i)) (+ 28 (.getHeight i)))
96 (.repaint panel 0 0 (.getWidth i) (.getHeight i)))))
97 69
98 (defn points->image 70 (defn points->image
99 "Take a sparse collection of points and visuliaze it as a 71 "Take a sparse collection of points and visuliaze it as a
100 BufferedImage." 72 BufferedImage."
101 73