开发者

Convert com.lowagie.text.Image to BufferedImage

开发者 https://www.devze.com 2023-02-23 04:49 出处:网络
How can I convert com.lowagie.text.Image to BufferedImage successfully. Please help me. 开发者_运维问答com.lowagie.text.Image itemImg=getHeaderImage(true);

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

精彩评论

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