Search code examples
clojureclojure-java-interoptga

Clojure read TGA witout libraries


I want to read TGA file to BufferedImage. How I can do it without libraries?

Now there is function:

(defn load-image [filename]
  (ImageIO/read (File. filename)))

This function read jpeg file successfully, but return nil instead of BufferedImage for TGA file.


Solution

  • The easiest thing would be still to use a library, for example TwelveMonkeys. In your project.clj (if you are using Leiningen), add:

    {:dependencies [... [com.twelvemonkeys.imageio/imageio-tga "3.4.1"]]}
    

    Then, in the code:

    (ImageIO/scanForPlugins)
    
    (defn load-image [filename]
      (ImageIO/read (File. filename)))
    

    This will work for valid TGA files.