|
Here is a modification that works for me: In PdfGraphics2D.java (line #1151) -------------------------------------------------------- public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer) { waitForImage(img); double dwidth = (double)dx2-dx1; double dheight = (double)dy2-dy1; double swidth = (double)sx2-sx1; double sheight = (double)sy2-sy1; //if either width or height is 0, then there is nothing to draw if (dwidth == 0 || dheight == 0 || swidth == 0 || sheight == 0) return true; double scalex = dwidth/swidth; double scaley = dheight/sheight; double transx = sx1*scalex; double transy = sy1*scaley; AffineTransform tx = AffineTransform.getTranslateInstance(dx1-transx,dy1-transy); tx.scale(scalex,scaley); //--------------------------------------------------- Shape saveClip = null; if (sx1 != 0 || sy1 != 0 || swidth != img.getWidth(null) || sheight != img.getHeight(null)) { saveClip = getClip(); clipRect(dx1, dy1, (int)dwidth, (int)dheight); } drawImage(img, null, tx, null, observer); if (saveClip != null) setClip(saveClip); /* BufferedImage mask = new BufferedImage(img.getWidth(observer), img.getHeight(observer), BufferedImage.TYPE_BYTE_BINARY); Graphics g = mask.getGraphics(); g.fillRect(sx1,sy1, (int)swidth, (int)sheight); drawImage(img, mask, tx, null, observer); g.dispose(); */ //--------------------------------------------------- return true; } PdfGraphics2D is full of limitations and when it comes to transparency even more so. This is complex to do it right and there will be no fix unless someone contributes with that fix.Paulo ----- Original Message ----- From: "Arnaud Masson" <[EMAIL PROTECTED]> To: <[email protected]> Sent: Saturday, August 25, 2007 4:55 PM Subject: [iText-questions] PdfGraphics2D.drawImage and alpha componentHello, I am using itext 2.0.4 which is really a cool library. But I have a problem with the following version of drawImage in PdfGraphics2D: boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer) It seems that when the input Image has transparency (like a BufferedImage of type TYPE_INT_ARGB), this method removes alpha information. It's probably because it makes internally a temporary BufferedImage with the pixel format TYPE_BYTE_BINARY. There is no problem with other versions of drawImage like: boolean drawImage(Image img, int x, int y, ImageObserver observer) This may be related to http://sourceforge.net/mailarchive/message.php?msg_id=loom.20070426T142627-378%40post.gmane.org I don't have the source for the library that makes the call to the wrong drawImage(), I just pass a Graphics2D, so it is no easy to fix. Moreover the constructor of PdfGraphics2D is not public. I have found a workaround: create proxy Graphics2D to wrap an existing PdfGraphics2D , so that the wrong drawImage() can be patched. Is there an other solution? Will this problem be fixed in a next release of itext? Thanks. Arnaud |
begin:vcard fn:Arnaud Masson n:Masson;Arnaud org:KIKA Medical;R&D adr:;;;Nancy;;54000;France email;internet:[EMAIL PROTECTED] x-mozilla-html:TRUE url:http://www.kikamedical.com version:2.1 end:vcard
------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________ iText-questions mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/itext-questions Buy the iText book: http://itext.ugent.be/itext-in-action/
