안녕하세요 모두 개체를 사용하려고 할 때마다 ImageIO.createImageInputStream
을 사용하면 예외, 경고 또는 오류없이 간단히 null
을 반환합니다. 함수에 다른 데이터 형식을 전달하려고 시도했지만 간단한 File
및 InputStream
이 반환되었지만 둘 다 null
이 반환되었습니다. 적절한 ImageInputStreamSpi
이 없다면이 함수는 null
을 반환 할 것이지만 그 파일은 습지 표준 JPEG이며 확실하게 Java는 이러한 형식의 서비스 공급자와 함께 제공됩니까? 시간 내 주셔서 감사합니다.ImageIO.createImageInputStream null을 반환 계속 유지
/**
* 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;
}
아니라 깨끗한 코드를 여기에 게시 그래서 우리는 당신이 내 질문에 대답하지 않았다 제외 : – FearUs
을 도울 수, 당신은 나에게 내가했던 다른 솔루션을 준 이미 사용하고 있습니다. 아래에서 자세히 설명했듯이 ... 여전히 문제가있는 원래의 질문은 아직 대답하지 않은 채로 남아 있습니다. –
나는 같은 문제가 있습니다. 어떤 이유에서 이클립스에서 MacOSX 1.6에서 작동하지만, 데비안 리눅스 환경에서는 생산에 실패합니다. 내 응용 프로그램은 Equinox 및 Jetty 서블릿 컨테이너를 기반으로하는 OSGI 기반 웹 응용 프로그램입니다. 지금까지 읽은 모든 것은 JAI와 OSGI (http://stackoverflow.com/questions/1493199/running-jai-in-osgi)와 관련이있는 것 같습니다. 그러나 나는 아직 그것을 풀지 않았다. – Christoph