【发布时间】:2016-11-16 10:18:49
【问题描述】:
如何将字节数组转换为itext pdf中的图像并以pdf格式显示。 这就是我正在做的,但我得到空指针异常..
Base64 decoder = new Base64();
byte[] imageByte = decoder.decode(imageInBase64EncodedString);
Image image = null;
try {
image = Image.getInstance(imageByte);
} catch (BadElementException e1) {
e1.printStackTrace();
} catch (MalformedURLException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
try {
image.scalePercent(15f); <-----Here i am getting NullPointer Exception
image.scaleAbsoluteWidth(520f);
image.setAbsolutePosition(40f,725f);
document.add(image);
}catch(Exception e){
e.printStackTrace();
}
我不明白为什么即使我传递了字节也没有创建图像。
【问题讨论】:
-
上面的
printStackTrace调用是否触发了? -
请回复@mkl no。
-
@DanCornilescu Ty 发表评论,但我不要求空指针异常。我的意思是为什么当我传递字节数组时图像为空。
-
请分享
imageInBase64EncodedString的值;否则我们无法回答您的问题。