ImageIO.createImageInputStream продолжает возвращать значение null

Всем привет, Каждый раз, когда я пытаюсь получить объект ImageInputStream , используя ImageIO.createImageInputStream , он просто возвращает null без исключений, предупреждений или ошибок. Я пробовал передавать функции разные типы данных, простой File и InputStream , но оба возвращали null . В документации говорится, что если не будет найдено подходящего ImageInputStreamSpi , функция вернет null , но файл является стандартным JPEG, и, конечно же, Java поставляется с поставщиком услуг для такого форматировать из коробки? Спасибо за ваше время.

/**
 * Reads in an image from a file and returns the image in a
 * {@code BufferedImage} object.
 *
 * @param source the file to create the {@code BufferedImage}
 * from.
 * @return the {@code BufferedImage} object representing the image
 * in {@code source}.
 */
private BufferedImage readImage( File source ) {
    // There is only one image in this file
    final int imageIndex = 0;
    BufferedImage image = null;

    try {
        // Get the ImageReader object for this filetype
        Iterator readers =
            ImageIO.getImageReaders( source );
        ImageReader reader = (ImageReader) readers.next();

        // Create an ImageInputStream object from the source image file
        ImageInputStream iis = ImageIO.createImageInputStream( source );
        // Raises IllegalArgumentException, because iis is null
        reader.setInput( iis, true );

        // Read the image file
        image = reader.read( imageIndex );
    } catch ( Exception exception ) {
        exception.printStackTrace();
        System.exit( -1 );
    }

    return image;
}
5
задан Sean Kelleher 27 February 2011 в 00:54
поделиться