4

I am building a program that compresses a given image and saves it as a JPEG. This is the error message I get:

Exception in thread "main" javax.imageio.IIOException: Can't read input file!
at javax.imageio.ImageIO.read(Unknown Source)
at JPEGCompression.main(JPEGCompression.java:23) 

Here is my main:

public class JPEGCompression {

public static void main(String[] args) throws IOException{

    String imageFile = "/tmp/garden.png";
    BufferedImage i = ImageIO.read(new File(imageFile)); // this line produces the error
    showImage("Original Image", i);

    compressAndShow(i, 0.7f);


}
Robin Green
  • 32,079
  • 16
  • 104
  • 187
pacman4565
  • 125
  • 1
  • 1
  • 8

2 Answers2

0

I have also met this problem. The answer is that the model of the picture is wrong. So you should change the model of the picture from 'CMYK' TO 'RGB'. CMYK is for printer, and RGB is for computer. You can use photoshop or imageMagick to get it done.

Unihedron
  • 10,902
  • 13
  • 62
  • 72
yuanfang
  • 69
  • 4
-1

You have no checks for if the file exists / have permissions for the file, that would be my first debugging step.

Also try the following: String imageFile = "./tmp/garden.png";

I always put a . before my slash to tell it I'm talking about the current directory, though I don't think it is required.

lucke84
  • 4,516
  • 3
  • 37
  • 58