Eric Clack
Eric Clack

Reputation: 1926

imagez load-image-resource complains "no implementation of method: :as-image"

On my Mac using [net.mikera/imagez "0.12.0"] when I run the example code to load an image I get an exception: user> (def ant (load-image-resource "mikera/image/samples/Ant.png")) CompilerException java.lang.IllegalArgumentException: No implementation of method: :as-image of protocol: #'mikera.image.protocols/ImageResource found for class: nil, compiling:(form-init214709365644880775.clj:59:16)

I'm running this code from within a Leiningen/Luminus project.

Perhaps I'm missing some dependencies for working with images?

My java version: java version "1.8.0_101" Java(TM) SE Runtime Environment (build 1.8.0_101-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)

Upvotes: 1

Views: 144

Answers (2)

Josh
Josh

Reputation: 4806

The library you are using is using the clojure function resource to load the image. Because the file Ant.png is not on the resource path, the call to resource is returning nil, which is why you're seeing this message. So, you need to add the path to your images as follows, in your project.clj:

:resource-paths ["/full/path/to/mikera/image/samples"]

Then in your code, reference the file as:

(def ant (load-image-resource "Ant.png"))

Upvotes: 1

Chris Murphy
Chris Murphy

Reputation: 6509

To fix create a directory called resources. It will be a sibling of a directory you probably already have src. Put your file "Ant.png" in this directory. Then you could simply have this:

(def ant (load-image-resource "Ant.png"))

Upvotes: 2

Related Questions