I am trying to find the width of a loaded image in clojure. In processing I would do this,

    PImage img=loadImage("image.jpg");
    int x=img.width;
    int y=img.height;

I tried to do this same in clojure but it won't work

   (defn loadwebimg []
     (let [filelst (map (fn [f] (.getName f)) (.listFiles (File. (str datadir))))
           imgf (first (shuffle filelst))
           webimg (load-image (str datadir imgf))
           ]
      (image webimg 0 0) 
      (println webimg.height))
有帮助吗?

解决方案

If webimg is an object when you would use the . special form to read its fields like you do for the file objects you use above it.

as user100464 points out:

(println webimg.height)

would become

(println (. webimg height)

or

(println (.height webimg))
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top