如何调用ImageReader类的setInput()?

时间:2012-03-27 14:13:29

标签: java javax.imageio

如何拨打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);

1 个答案:

答案 0 :(得分:1)

如果您的意思是调用读者变量中包含的ImageReader s上的方法,则可以循环使用它们:

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