我正在byte[]
从 DB 中读取数据并将其转换为缓冲图像。
当我尝试显示图像时,我得到一个NullPointerException
.
这是我坚持的代码部分:
conn = access.getCon();
sql = "select doc_size, mime_type_id, doc from endo_scope_doc where endo_scope_val_id ='"+idToProcess+"'";
stmt = conn.prepareStatement(sql);
ResultSet resultSet = stmt.executeQuery();
while (resultSet.next()) {
doc_size = resultSet.getLong(1);
mime_type_id = resultSet.getInt(2);
doc = resultSet.getBytes(3);
}
} catch (Exception ex) {
System.out.println(this.getClass().getName()+"."+ex.getStackTrace()[0].getMethodName()+" 4: "+ ex);
ex.printStackTrace();
throw new Exception("Cannot execute data retrieval for photo with SQL: "+sql,ex);
}
BufferedImage bufferedImage = null;
try {
bufferedImage = ImageIO.read(new ByteArrayInputStream(doc));
} catch (IOException e) {
e.printStackTrace();
}
Image jpeg = Image.getInstance(bufferedImage, null);
jpeg.scalePercent(40);
jpeg.setAlignment(Image.LEFT);
PdfPCell photoCell = new PdfPCell(jpeg);
iText 使用com.lowagie.text.Image
not java.awt.Image
,所以我找不到转换BufferedImage
为Image
.
这是错误:
java.lang.NullPointerException
at java.awt.image.PixelGrabber.<init>(Unknown Source)
at com.lowagie.text.Image.getInstance(Unknown Source)
at com.lowagie.text.Image.getInstance(Unknown Source)
at iwa.printScopeValPDF.doServlet(printScopeValPDF.java:211)
at iwa.printScopeValPDF.doGet(printScopeValPDF.java:277)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:627)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(