2013-04-30 99 views
1

雖然轉換InputStreamBufferedImage我得到下面的錯誤錯誤意外結束

byte[] imgBytes = decoder.decode(encodedStr); 

這條線被執行細並生成字節數組正確

InputStream in = new ByteArrayInputStream(imgBytes); 
BufferedImage bImageFromConvert = ImageIO.read(in); 

這條線是給出錯誤,因爲它無法正確讀取InputStream

Below is the error 
    javax.imageio.IIOException: Error reading PNG image data 
     at com.sun.imageio.plugins.png.PNGImageReader.readImage(Unknown Source) 
     at com.sun.imageio.plugins.png.PNGImageReader.read(Unknown Source) 
     at javax.imageio.ImageIO.read(Unknown Source) 
     at javax.imageio.ImageIO.read(Unknown Source) 
     at DecodeSignatureFile.generateImage(DecodeSignatureFile.java:252) 
     at DecodeSignatureFile.getContents(DecodeSignatureFile.java:176) 
     at DecodeSignatureFile.process(DecodeSignatureFile.java:322) 
     at DecodeSignatureFile.main(DecodeSignatureFile.java:334) 
Caused by: java.io.EOFException: Unexpected end of ZLIB input stream 
     at java.util.zip.InflaterInputStream.fill(Unknown Source) 
     at java.util.zip.InflaterInputStream.read(Unknown Source) 
     at java.io.BufferedInputStream.fill(Unknown Source) 
     at java.io.BufferedInputStream.read1(Unknown Source) 
     at java.io.BufferedInputStream.read(Unknown Source) 
     at java.io.DataInputStream.readFully(Unknown Source) 
     at com.sun.imageio.plugins.png.PNGImageReader.decodePass(Unknown Source) 
     at com.sun.imageio.plugins.png.PNGImageReader.decodeImage(Unknown Source) 
     ... 8 more 
+0

是否有可能您的解碼方法錯誤或** encodedStr **損壞? – 2013-04-30 08:49:23

+0

什麼是'解碼器'?你在這裏給我們提供了很少的信息。 – 2013-04-30 08:51:41

回答

0

錯誤可能發生在之前。在Java中,字符串encodedStr通常不適合保存二進制數據。將這些imgBytes與原始圖像進行比較。

當然,這取決於編碼和解碼。但其餘的看起來沒問題。