ImageIO 读取 ByteArrayInputStream 为空
ImageIO is null reading ByteArrayInputStream
我有这段代码
System.out.println ("fileData 1 -> " + fileData);
ByteArrayInputStream in = new ByteArrayInputStream(fileData);
System.out.println ("fileData 2 -> " + in);
try {
BufferedImage img = ImageIO.read(in);
System.out.println ("fileData 3 -> " + img);
....
这是我在控制台中看到的:
fileData 1 -> [B@7a677c
fileData 2 -> java.io.ByteArrayInputStream@203aa8
fileData 3 -> null
为什么 BufferedImage
为空且不抛出异常?
documentation表示可以为空:
Returns a BufferedImage as the result of decoding a supplied
InputStream with an ImageReader chosen automatically from among those
currently registered. The InputStream is wrapped in an
ImageInputStream. If no registered ImageReader claims to be able to
read the resulting stream, null is returned. [...]
我有这段代码
System.out.println ("fileData 1 -> " + fileData);
ByteArrayInputStream in = new ByteArrayInputStream(fileData);
System.out.println ("fileData 2 -> " + in);
try {
BufferedImage img = ImageIO.read(in);
System.out.println ("fileData 3 -> " + img);
....
这是我在控制台中看到的:
fileData 1 -> [B@7a677c
fileData 2 -> java.io.ByteArrayInputStream@203aa8
fileData 3 -> null
为什么 BufferedImage
为空且不抛出异常?
documentation表示可以为空:
Returns a BufferedImage as the result of decoding a supplied InputStream with an ImageReader chosen automatically from among those currently registered. The InputStream is wrapped in an ImageInputStream. If no registered ImageReader claims to be able to read the resulting stream, null is returned. [...]