3

I'm running the following command in my terminal to run the code stored in the following file:

java -cp clojure.jar clojure.main thumbmaker.clj

Where the content of thumbmaker.clj is (this code has been referenced at several places):

(import javax.imageio.ImageIO)
(import java.awt.image.BufferedImage)
(use '[clojure.java.io :only [as-file input-stream output-stream] :as io])

(defn make-thumbnail-generic [input new-filename width]
  (let [img (javax.imageio.ImageIO/read input)
        imgtype (java.awt.image.BufferedImage/TYPE_INT_ARGB)
        width (min (.getWidth img) width)
        height (* (/ width (.getWidth img)) (.getHeight img))
        simg (java.awt.image.BufferedImage. width height imgtype)
        g (.createGraphics simg)]
    (.drawImage g img 0 0 width height nil)
    (.dispose g)

(defn make-thumbnail-from-file [filename new-filename width]
  (make-thumbnail-generic filename new-filename width))

(make-thumbnail-from-file "thumb.png" "test.png" 100)

And I'm getting the following error:

Exception in thread "main" java.lang.IllegalArgumentException: No matching method found: read (thumbmaker.clj:0)

I have checked the import and use statements in the REPL independently and they seem to be accepted pretty fine.

I checked the Java reference for ImageIO and the read function is there.

I've gone through the Java-Interop writeup and this seems to be very much the standard way, so I can't figure out why the read is not working.

1 Answer 1

5

See http://docs.oracle.com/javase/1.5.0/docs/api/javax/imageio/ImageIO.html

javax.imageio.ImageIO/read expects a URL, File, InputStream or ImageInputStream. Not a string.

Doing (javax.imageio.ImageIO/read (as-file input)) solves the problem.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.