The clip() operation is for paths. As I recall, masks are just applied to other images. "Image A is a mask for Image B".
OTOH: you might be able to get what you're after with an extended graphics state: Blending Mode. Let me check the Holy Writ: http://www.adobe.com/content/dam/Adobe/en/devnet/pdf/pdfs/PDF32000_2008. pdf Ah. Okay, there's something called a "Colour Key Mask" defined in section 8.9.6.4: " In PDF 1.3, the Mask entry in an image dictionary may be an array specifying a range of colours to be masked out. Samples in the image that fall within this range shall not be painted, allowing the existing background to show through. NOTE 1 The effect is similar to that of the video technique known as chroma-key. " Not really what you want either. Lets just make sure I've got the right idea here: You want to mask out some Other Thing based on the pixel colors of a given image. Is this an alpha channel/blending type thing, or an all-or-nothing "mask" thing? I'm pretty sure you'll need to use PDF's transparency/blending system. PDF supports a number of blending modes, but it sounds like you'll want... err... I'm really not sure here. The blend modes are all listed as mathematical formulae with no real description of What It Looks Like. Hrm... What you're after might be a Transparency Group(11.4), using a Soft Mask(11.5). That sounds pretty promising. So how do you build one in iText? Lesseehere... Ah! Chapter 10 of iText in Action (2nd edition) covers both transparency groups and hard-n-soft image masks. Does this look like what you're after? http://www.flickr.com/photos/itextinaction/4330326988 If you scroll down this page a bit, http://itextpdf.com/book/chapter.php?id=10, you'll see a number of transparency and mask related examples. --Mark Storer Senior Software Engineer Cardiff.com import legalese.Disclaimer; Disclaimer<Cardiff> DisCard = null; > -----Original Message----- > From: Matteo [mailto:[email protected]] > Sent: Tuesday, December 28, 2010 6:37 AM > To: [email protected] > Subject: [iText-questions] Image clipping > > > Hi all, > I have a mask in a png file and I need to create different > objects of different colors with this same mask. > I am creating on a template a rectangle filled with the > required color and then an image starting from the template. > On a content i clip the mask but then adding the rectangle > image the clipping is not working and the full rectangle > appears instead of the masked one. > > What I am doing wrong? > > Thanks. > > This is the code: > > over = Pdfwriter.getDirectContent(); > over.saveState(); > PdfTemplate content = over.createTemplate(186,71); > content.rectangle (0,0, 186, 71); content.setColorFill(new > Color (0x999999)); content.setColorStroke(new Color > (0x999999)); content.fillStroke(); Image img = > Image.getInstance(content); Image mask = > Image.getInstance("shape03.png"); mask.scaleToFit(187, 71); > over.addImage(mask, mask.getScaledWidth(), 0,0, > mask.getScaledHeight(),0,0); over.clip(); over.newPath(); > over.addImage(img,img.getScaledWidth(), 0,0, > img.getScaledHeight(),0,0); over.restoreState(); > > Cheers, > Matteo > > -- > View this message in context: > http://itext-general.2136553.n4.nabble.com/Image-clipping-tp31 66048p3166048.html > Sent from the iText - General mailing list archive at Nabble.com. > > -------------------------------------------------------------- > ---------------- > Learn how Oracle Real Application Clusters (RAC) One Node > allows customers to consolidate database storage, standardize > their database environment, and, should the need arise, > upgrade to a full multi-node Oracle RAC database without > downtime or disruption http://p.sf.net/sfu/oracle-sfdevnl > _______________________________________________ > iText-questions mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/itext-questions > > Many questions posted to this list can (and will) be answered > with a reference to the iText book: > http://www.itextpdf.com/book/ Please check the keywords list > before you ask for examples: http://itextpdf.com/themes/keywords.php > > ------------------------------------------------------------------------------ Learn how Oracle Real Application Clusters (RAC) One Node allows customers to consolidate database storage, standardize their database environment, and, should the need arise, upgrade to a full multi-node Oracle RAC database without downtime or disruption http://p.sf.net/sfu/oracle-sfdevnl _______________________________________________ iText-questions mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/itext-questions Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/ Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php
