开发者

Convert com.lowagie.text.Image to BufferedImage

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....


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜