如何调用setInput类的ImageReader
下面是我的代码:

ImageInputStream iis = ImageIO.createImageInputStream(newByteArrayInputStream(cipherData));
Iterator<ImageReader> readers=ImageIO.getImageReaders(iis);
Iterator<ImageReader> readers=ImageIO.getImageReaders(iis);
System.out.println("readers="+readers);

最佳答案

如果要在readers变量中包含的ImageReader上调用方法,则可以遍历它们:

for (Iterator<ImageReader> it=ImageIO.getImageReaders(iis); it.hasNext();) {
    ImageReader reader = it.next();
    readers.setInput(someObject);
}


编辑

如果只想要第一个元素:

Iterator<ImageReader> it=ImageIO.getImageReaders(iis);
ImageReader reader = null;
if (it.hasNext()) {
    reader = it.next();
}
//you probably want to check for null here to make sure there was one element

10-08 19:26