I am using Graphics2D itext feature and draw image with g2.drawImage(x, y, null). If i load this image using ImageIO.read() image looks black and white in generated PDF. But Toolkit.getDefaultToolkit().createImage() works fine. Here is the code:
public static final String filename = "dummy.pdf";
public static void main(String[] args) {
try {
Document doc = new Document();
PdfWriter writer = 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 i = 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 for another gif the ImageIO works fine, and Toolkit does not work. But all images look fine on screen. Why the way i load image affects the result in PDF?
P.S. For the clear reasons i am using LGPL iText (2.0.4, 2.1.7, 4.2.0). UPD: works fine on iText-5.3.5, that i can not use :-(