如何將字節數組轉換爲itext pdf格式的圖像並以pdf格式顯示。 這是我在做什麼,但是我得到空指針異常..如何使用itextPdf將字節數組轉換爲圖像並以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
可能的重複[什麼是NullPointerException,以及如何解決它?](http://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it ) –
Ty for reply guys @mkl no。 –