java - iText makes color image appears black and white -
i using graphics2d itext feature , draw image g2.drawimage(x, y, null). if load image using imageio.read() image looks black , white in generated pdf. toolkit.getdefaulttoolkit().createimage() works fine. here code:
public static final string filename = "dummy.pdf"; public static void main(string[] args) { seek { document doc = new document(); pdfwriter author = pdfwriter.getinstance(doc, new fileoutputstream(filename)); writer.setpdfversion(pdfwriter.version_1_5); doc.open(); pdfcontentbyte cb = writer.getdirectcontent(); graphics2d g2 = cb.creategraphics(1654, 1168); draw(g2); doc.close(); system.out.println("done!"); } catch(exception e) { e.printstacktrace(); } } private static void draw(graphics2d g2) throws exception { g2.setcolor(color.red); g2.fill(new rectangle2d.double(0, 0, 100, 100)); bufferedimage img = imageio.read(new file("speedy2bigclr.gif")); bufferedimage bi = tobufferedimage(img); image = makecolortransparentandbw(bi, color.white); image iii = toolkit.getdefaulttoolkit().createimage("speedy2bigclr.gif"); g2.translate(0, 300); g2.scale(0.3, 0.3); g2.drawimage(img, 0, 0, null); } }
unfortunately gif imageio works fine, , toolkit not work. images fine on screen. why way load image affects result in pdf?
p.s. clear reasons using lgpl itext (2.0.4, 2.1.7, 4.2.0). upd: works fine on itext-5.3.5, can not utilize :-(
java pdf awt itext javax.imageio
No comments:
Post a Comment