Convert com.lowagie.text.Image to BufferedImage

笑着哭i 提交于 2019-12-10 22:49:02

问题


How can I convert com.lowagie.text.Image to BufferedImage successfully. Please help me.

            com.lowagie.text.Image itemImg=getHeaderImage(true);    

            ByteArrayOutputStream bas = new ByteArrayOutputStream();        
            ImageIO.write((RenderedImage) itemImg,"png", bas);
            byte[] data = bas.toByteArray();            

            InputStream in = new ByteArrayInputStream(data);            
            BufferedImage image = ImageIO.read(in); 

Now I get the exception "java.lang.ClassCastException: com.lowagie.text.ImgRaw cannot be cast to java.awt.image.RenderedImage"

Can anyone help me....


回答1:


iText doesn't do that, no. iText's image class is for bringing images INTO pdf files, not out of them.

Having said that, you can get the bytes, bits per component, and so forth out of an ImgRaw and use that information to build an AWT image.



来源:https://stackoverflow.com/questions/5576588/convert-com-lowagie-text-image-to-bufferedimage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!