Java ImageIO适用于W10但不适用于W8

时间:2016-11-14 17:05:52

标签: java image reader

所以我编写了这个程序来读取图像并改变它的一些颜色:

public class MorphImage {
    private final String URL = "pic1.jpg";

public static void main(String[] args) {
    try {
        new MorphImage();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

public MorphImage() throws IOException {
    BufferedImage image = readImage(URL);
    pointOp(image, 50, 75);
}

/**
 * Read and create a bufferedImage from an URL.
 * 
 * @param URL
 * @return
 */
private BufferedImage readImage(String URL) {
    URL url = getClass().getResource(URL);
    File file = new File(url.getPath());
    BufferedImage bimg = null;
    try {
        bimg = ImageIO.read(file);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return bimg;

}

/**
 * Uses a BufferedImage to create a new copy of it with altered values.
 * 
 * @param img
 * @throws IOException
 */
private void pointOp(BufferedImage img, int con, int brig) throws IOException {
    int width = img.getWidth();
    int height = img.getHeight();
    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    WritableRaster inraster = img.getRaster();
    WritableRaster outraster = image.getRaster();
    for (int i = 0; i < width; i++)
        for (int j = 0; j < height; j++) {
            int value = inraster.getSample(i, j, 0);
            outraster.setSample(i, j, 0, 255 - value);
        }
    ImageIO.write(image, "PNG", new File("Morphed " + URL));
    System.out.println("Morphed");

}


}

它在我运行Windows 10的笔记本电脑上工作得很好,但当我将repo克隆到运行Windows 8.1的电脑上时,它再也找不到图像“pic1.jpg”了。它抛出IIOException无法读取输入文件。两台计算机都运行相同的JDK和Eclipse设置。我把所有文件放在同一个包中:

imager
      -src
         -main
             -MorphImage.java
             -pic1.jpg

有人知道这里有什么问题吗?

0 个答案:

没有答案