我正在从DB中读取byte[]
并将其转换为缓冲图像。
当我尝试显示图像时,我得到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
而非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(