熊田貢 <kumata-mit <at> obun.jp> writes: > > Hello all, > > I have a question about soft-mask. > I know there is a sample code "SoftMask.java", but I > want to know how to achieve soft-mask using gradation > composed of path lines as mask. > > For example, if I have the following mask; > > for(int i=0; i<10; i++) { > template.setLineWidth(10-i); > template.setGrayStroke(1-(0.1f*i)); > template.ellipse(0, 0, 100, 100); > template.stroke(); > } > template.ellipse(0, 0, 100, 100); > template.clip();
Clipping and masking are two different things. > how to apply the mask to a photo? > Is it impossible? No, but it isn't directly supported by iText. You'll need to read the PDFReference and do some direct PdfDictionary manipulation. > > I tried "PdfGState#setAlphaIsShape(false)", but I could > not get good result. > You'll need to create an XObject Form (a PdfTemplate) with the mask shape you want, and build a "soft mask dictionary", as defined in the Pdf Reference (chapter 7.5, table 7.10). Something like this: << /Type /Mask /S /Luminosity /G 999 0 R %% an indirect reference to that XObject Form I mentioned >> You then write this dictionary into the PdfGState's /SMask key. The XObject Form houses your blended path for the mask. I strongly suggest you draw it in DeviceG (gray) color. You'll need to set the PdfTemplate's PdfTransparencyGroup. PdfGState state = new PdfGState(); PdfDictionary maskDict = new PdfDictionary(); maskDict.put( PdfName.TYPE, PdfName.MASK ); maskDict.put( PdfName.S, new PdfName( "Luminosity" ) ); maskDict.put( PdfName.G, template.getIndirectReference() ); state.put( PdfName.SMASK, maskDict ); PdfTransparencyGroup transGroup = new PdfTransparencyGroup(); transGroup.put( PdfName.CS, PdfName.DEVICEGRAY ); template.setGroup( transGroup ); That should do it, though I'm none too certain about the DEVICEGRAY entry in the transGroup. It may not be necessary, or it may need to be DEFAULTGRAY instead. (hmm... I really ought to charge for this stuff ;) --Mark Storer Senior Software Engineer Cardiff.com #include <disclaimer> typedef std::disclaimer<Cardiff> DisCard; ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ iText-questions mailing list iText-questions@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/itext-questions Do you like iText? Buy the iText book: http://www.1t3xt.com/docs/book.php Or leave a tip: https://tipit.to/itexttipjar