Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IIOException Invalid argument to native writeImage #21

Open
pandeiro opened this issue Aug 7, 2015 · 3 comments
Open

IIOException Invalid argument to native writeImage #21

pandeiro opened this issue Aug 7, 2015 · 3 comments

Comments

@pandeiro
Copy link

pandeiro commented Aug 7, 2015

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?

@mikera
Copy link
Owner

mikera commented Aug 8, 2015

Is it possible you are hitting this issue?

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

@mikera
Copy link
Owner

mikera commented Aug 8, 2015

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

@deadghost
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants