imagez icon indicating copy to clipboard operation
imagez copied to clipboard

IIOException Invalid argument to native writeImage

Open pandeiro opened this issue 10 years ago • 3 comments

In a basic leiningen project that includes a file sample.jpg:

user> (require '[clojure.java.io :as io] '[mikera.image.core :as img])
nil
user> (io/file "sample.jpg")
#<File sample.jpg>
user> (img/load-image (io/file "sample.jpg"))
#<BufferedImage BufferedImage@7491c6b: type = 2 DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=ff000000 IntegerInterleavedRaster: width = 1000 height = 667 #Bands = 4 xOff = 0 yOff = 0 dataOffset[0] 0>
user> (img/save (img/load-image (io/file "sample.jpg")) "other.jpg")
IIOException Invalid argument to native writeImage  com.sun.imageio.plugins.jpeg.JPEGImageWriter.writeImage (JPEGImageWriter.java:-2)
user> 

Am I doing something wrong?

pandeiro avatar Aug 07 '15 12:08 pandeiro

Is it possible you are hitting this issue?

http://stackoverflow.com/questions/3432388/imageio-not-able-to-write-a-jpeg-file

mikera avatar Aug 08 '15 05:08 mikera

P.S. I normally use .png images pretty much exclusively - best to keep things lossless while you are doing image processing work.

mikera avatar Aug 08 '15 05:08 mikera

I also hit this issue. Switching from OpenJDK to Oracle got me past this specific exception; however, I ran into another problem. When I read a jpg image and save it as a jpg image (yes jpg -> jpg), it comes out as all black when I open it using Ristretto Image Viewer on Xubuntu. When I open it in Firefox, it comes out pink.

From SO comments:

BTW, OpenJDK does have a native JPEG encoder. And if you try to save 32-bit-color file - it fails. And Sun JDK does not fail, but form tinted file. Not sure what is better. – Andrey Regentov Apr 25 '13 at 11:02

If you are getting a pink effect, it is likely because you use a BufferedImage with an alpha-channel while JPG does not support that. Make sure you use a BufferedImage.TYPE_INT_RGB and not BufferedImage.TYPE_INT_ARGB – Guillaume Polet Jul 31 '12 at 13:26

deadghost avatar Oct 10 '15 14:10 deadghost