2010-08-03 2 views
3

저는 Clojure ref에 저장된 BufferedImage를 드로잉하여 몇 시간 씩 저의 드로잉 방법을 사용하려고했습니다. 이 경우는 JPanel입니다). 불행히도, 이것은 전혀 효과가 없습니다.Clojure/Swing/Java의 BufferedImage 및 ImageObserver에 문제가 발생했습니다.

내 코드는이 (아래 깎았지만, 관련 부품 보여주는 :

(defn create-graph 
    "Data-ref is [xs ys], buffered-image-ref holds the basic graph." 
    [data-ref buffered-image-ref & {:keys [width height image]}] 
    (proxy [JPanel] 
     [] 
    (getPreferredSize [] (Dimension. width height)) 
    (paintComponent [g] 
        (proxy-super paintComponent g) 
        (if-not @buffered-image-ref 
         (dosync 
         (ref-set buffered-image-ref 
           (xy-plot2 
           (first @data-ref) 
           (second @data-ref) 
           (.getGraphics 
            (BufferedImage. width height 
                BufferedImage/TYPE_INT_ARGB)) 
           :axis? true 
           :width width 
           :height height)))) 
        (.drawImage g @buffered-image-ref 
           0 0 
           (proxy [ImageObserver] 
             [] 
             (imageUpdate [] 
              (proxy-super imageUpdate))))))) 

그리고, 아래, XY-plot2 (문제가 될 나타나지 않습니다,하지만 난 그것을 포함하는 것 완전성 :.

(defn xy-plot2 
    "Draws an xy-plot in the given Graphics context. 
    'xs must be equal in length to 'ys." 
    [xs ys gfx 
    & {:keys [color max-y axis? y-buffer width height] 
    :or {color Color/RED y-buffer 0}}] 
    (let [h (/ height 2) ;; since we have -h to h (not 0 to h) 
     w width ;; since we graph 0 to w 
     len (count xs) 
     min-x (apply min xs) 
     xs (if-not (zero? min-x) 
      (map #(- % min-x) xs) 
      xs) 
     max-y (or max-y (apply max ys)) 
     max-x (apply max xs)] 
    (.setColor gfx color) 
    (dorun ;; this is the key part, along with scale-xs and draw-l 
    (take len 
      (iterate (partial d-line gfx h) 
        [(scale-xs xs w 0) 
        (scale-xs ys h y-buffer)]))) 
    (and axis? (or (.setColor gfx Color/BLACK) (.drawLine gfx 0 h w h))) 
    gfx)) 

내가 이것을 실행하면, 나는 내가 paintComponent() 방법의 마지막 부분에 엉망했습니다 믿기에 이르게이 오류를 얻을

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: 
No matching method found: drawImage for class sun.java2d.SunGraphics2D 
을 0

나는 ImageObservernil으로 바꾸려고했지만 아무런 노력을하지 못했습니다. 다른 arg 명령을 시도했습니다. 다른 유형의 Graphics 클래스에 대해서는 다른 drawImage 메서드에 대해 시도했습니다. 모두 소용 없다.

죄송합니다. 이해하기 어려운 약간의 소리를 들려 주면이 버그가 나를 괴롭 히고 있습니다. 필요할 경우 아침에 편집하겠습니다.

은 너무 많이, 너무 이삭

답변

3

감사 그것은 버퍼 이미지-REF가 BufferedImage의의 그래픽으로 설정되어 처럼 보이는이 아니라 이미지 자체.

+0

그게 전부입니다. 좋은 신. 이 약을 먹으면 도움이 될까요? 또한 쿠키를 제공하려는 사람 중 한 명입니까? :) 고마워, 분명히 기술을 검토하는 나쁜 코드가있다. – Isaac

관련 문제