ImageIO.createImageInputStream Keeps Returning null

后端 未结 1 1558
野性不改
野性不改 2021-01-19 03:25

Hey all, Whenever I try to get an ImageInputStream object using ImageIO.createImageInputStream it simply returns null with no exceptio

相关标签:
1条回答
  • 2021-01-19 04:24

    Why are you doing all that?? you can simply do this:

    image = ImageIO.read(source);
    

    No Iterators, ImageInputStreams... no nothing !

    EDIT: Since you insist, your code is not working because you're sending a File to ImageIO.getImageReaders() instead of a ImageInputStream. SO your code should look something like that:

    ImageInputStream iis = ImageIO.createImageInputStream(source);
    Iterator readers = ImageIO.getImageReaders(iis);
    ImageReader reader = (ImageReader) readers.next();
    
    reader.setInput(iis, false);
    image = reader.read(imageIndex);
    
    0 讨论(0)
提交回复
热议问题