【发布时间】:2020-07-05 00:33:51
【问题描述】:
我正在尝试使用 Clojure Quil 库创建加载图像到小程序。当我存储 load-image 引用并将其与image 调用一起使用时,在加载期间它可以工作。但是当我加载并在draw中显示时它不起作用。
这行得通:
(ns img-demo.core
(:require [quil.core :as q]))
(def img (ref nil))
(def img-url "https://dummyimage.com/100x100/2c3e50/ffffff.png")
(defn setup []
(q/background 0)
(dosync (ref-set img (q/load-image img-url))))
(q/defsketch example
:title "image demo"
:setup setup
:draw #(q/image @img 0 0)
:size [600 600])
这不起作用,
(ns img-demo.core
(:require [quil.core :as q]))
(def img-url "https://dummyimage.com/100x100/2c3e50/ffffff.png")
(q/defsketch example
:title "image demo"
:draw #(q/image (q/load-image img-url) 0 0)
:size [600 600])
在后一种情况下,我知道应该在quil.applet/with-applet 内部调用load-image。由于它发生在defsketch 内部,我希望它会自动得到处理或至少抛出一个 NPE。为什么它不起作用?
【问题讨论】: