將inputStream轉換爲bufferImage存在問題。 BufferedImage crfPersonImg始終爲空,異常發生在行柵格柵格= reader1.readRaster(0,null);。這是到目前爲止我的代碼javax.imageio.IIOException:不是JPEG流(開頭爲:0x0003,預計SOI:0xffd8)
//code for getting ByteArray From Blob column in Oracle DB.
List<Object[]> userRoleList = commonDao.findByNativeSQL(selectSQL
, new Object[] {examCd, examPeriod, fromMemNo, toMemNo});
for(Object[] row : userRoleList){
CertificateDtlsVO cdObj = new CertificateDtlsVO();
cdObj.setExmCd(Integer.parseInt(row[0].toString()));
cdObj.setExmDsc(row[1].toString());
cdObj.setMemNo(row[2].toString());
cdObj.setMemNm(row[3].toString());
cdObj.setCertNo(row[4].toString());
cdObj.setCertDt(row[5].toString());
cdObj.setPrtNo(row[6].toString());
cdObj.setSylCd(row[7].toString());
cdObj.setNumOfTime(Integer.parseInt(row[8].toString()));
cdObj.setMemType(row[9].toString());
cdObj.setClassGrade(row[10].toString());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(row[11]);
cdObj.setPhoto(baos.toByteArray());
baos = new ByteArrayOutputStream();
oos = new ObjectOutputStream(baos);
oos.writeObject(row[12]);
cdObj.setSign(baos.toByteArray());
cdObj.setPhotoBuffImg(ImageIO.read(new ByteArrayInputStream(baos.toByteArray())));
oos.flush();
oos.close();
memCertfDtlsList.add(cdObj);
}
//代碼轉換爲字節數組BufferImage
InputStream in = new ByteArrayInputStream(photo);
Iterator<ImageReader> readers = ImageIO.getImageReadersByFormatName("JPEG");
ImageReader reader1 = null;
while (readers.hasNext()) {
reader1 = readers.next();
if (reader1.canReadRaster()) {
break;
}
}
//Stream the image file
ImageInputStream input = ImageIO.createImageInputStream(in);
reader1.setInput(input);
//Read the image raster
Raster raster = reader1.readRaster(0, null);
//Create a new RGB image
BufferedImage bi = new BufferedImage(raster.getWidth(), raster.getHeight(),
BufferedImage.TYPE_4BYTE_ABGR);
//Fill the new image with the old raster
bi.getRaster().setRect(raster);
BufferedImage crfPersonImg = ImageIO.read(in);
javax.imageio.IIOException:爲0x0003,預計SOI:不是一個JPEG視頻流(開頭爲: 0xffd8) 在com.twelvemonkeys.imageio.plugins.jpeg.JPEGSegmentImageInputStream.streamInit(JPEGSegmentImageInputStream.java:247) 在com.twelvemonkeys.imageio.plugins.jpeg.JPEGSegmentImageInputStream.fetchSegment(JPEGSegmentImageInputStream.java:71) 在融爲一體。十二monkeys.imageio.plugins.jpeg.JPEGSegmentImageInputStream.repositionAsNecessary(JPEGSegmentImageInputStream.java:267)
我試圖直接使用'ImageIO.read()'和'ImageReader.readRaster()'來讀取文件,並且在兩種情況下都能正常工作。我不明白你爲什麼需要這兩個,但他們工作。所以,我會懷疑問題出在您沒有顯示的代碼中。喜歡什麼是照片?一個'byte'數組?它是如何填充的? – haraldK
** InputStream in = new ByteArrayInputStream(photo)**我用來將photo byte []轉換爲inputStream。 [這是我的第二個圖像樣本](http://fotoforensics.com/analysis.php?id=70c5fd394b5e086bdc9b74db7944cc6c222c7818.8021&fmt=orig) –
@haraldK ** InputStream in = new ByteArrayInputStream(photo)**我用於將照片字節[]轉換爲inputStream。 [這是我的第二個圖像樣本](http://fotoforensics.com/analysis.php?id=70c5fd394b5e086bdc9b74db7944cc6c222c7818.8021&fmt=orig)和[Byte Array](https://ufile.io/7iqst)。我通過dataBase oracle Blob列填充。它的jpeg fomate。 –