1

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.

VsSekorin
  • 355
  • 1
  • 3
  • 17
  • 1
    You can try to adapt one of the Java solutions https://stackoverflow.com/questions/1514035/java-tga-loader to Clojure if you don't want to use a library. – Aleph Aleph Oct 09 '18 at 20:04
  • @AlephAleph It solution of 2009. There are not more fluent solution? And what is library I can use? I try to use Quil, but it is not resolve the problem of reading tga. – VsSekorin Oct 09 '18 at 20:09
  • 1
    TGA hasn't been included in Java's standard library since 2009 as far as I know, and the format hasn't really changed, so what is wrong with 2009's answers? You can translate the Java code in those answers to Clojure. Would be better to use a library for that to be sure to catch all corner cases though - please see my answer. – Aleph Aleph Oct 09 '18 at 21:21

1 Answers1

1

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.

Aleph Aleph
  • 5,215
  • 2
  • 13
  • 28