Java Code Examples for com.lowagie.text.Image#makeMask()

The following examples show how to use com.lowagie.text.Image#makeMask() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SoftMaskTest.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Demonstrates the Transparency functionality.
 */
@Test
public  void main() throws Exception {
	// step 1: creation of a document-object
	Document document = new Document(PageSize.A4, 50, 50, 50, 50);
	// step 2: creation of a writer
	PdfWriter writer = PdfWriter.getInstance(document,PdfTestBase.getOutputStream("softmask.pdf"));
	// step 3: we open the document
	document.open();
	// step 4: content
	PdfContentByte cb = writer.getDirectContent();
	String text = "text ";
	text += text;
	text += text;
	text += text;
	text += text;
	text += text;
	text += text;
	text += text;
	text += text;
	document.add(new Paragraph(text));
	Image img = Image.getInstance(PdfTestBase.RESOURCES_DIR	+ "otsoe.jpg");
	img.setAbsolutePosition(100, 550);
	byte gradient[] = new byte[256];
	for (int k = 0; k < 256; ++k) {
		gradient[k] = (byte) k;
	}
	Image smask = Image.getInstance(256, 1, 1, 8, gradient);
	smask.makeMask();
	img.setImageMask(smask);
	cb.addImage(img);
	cb.sanityCheck();
	// step 5: we close the document
	document.close();
}
 
Example 2
Source File: ImageMasksTest.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
    * Applying masks to images.
 */
@Test
public void main() throws Exception {
       
       
       Document document = new Document(PageSize.A4, 50, 50, 50, 50);
       try {
           PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream( "maskedImages.pdf"));
           
           document.open();
           Paragraph p = new Paragraph("Some text behind a masked image.");
           document.add(p);
           document.add(p);
           document.add(p);
           document.add(p);
           document.add(p);
           document.add(p);
           document.add(p);
           document.add(p);
           document.add(p);
           document.add(p);
           
           document.add(p);
           document.add(p);
           document.add(p);
           document.add(p);
           document.add(p);
           document.add(p);
           document.add(p);
           document.add(p);
           document.add(p);
           document.add(p);
           document.add(p);
           document.add(p);
           document.add(p);
           document.add(p);
           document.add(p);
           PdfContentByte cb = writer.getDirectContent();
           byte maskr[] = {(byte)0x3c, (byte)0x7e, (byte)0xe7, (byte)0xc3, (byte)0xc3, (byte)0xe7, (byte)0x7e, (byte)0x3c};
           Image mask = Image.getInstance(8, 8, 1, 1, maskr);
           mask.makeMask();
           mask.setInverted(true);
           Image image = Image.getInstance(PdfTestBase.RESOURCES_DIR +"otsoe.jpg");
           image.setImageMask(mask);
           image.setAbsolutePosition(60, 550);
           // explicit masking
           cb.addImage(image);
           // stencil masking
           cb.setRGBColorFill(255, 0, 0);
           cb.addImage(mask, mask.getScaledWidth() * 8, 0, 0, mask.getScaledHeight() * 8, 100, 450);
           cb.setRGBColorFill(0, 255, 0);
           cb.addImage(mask, mask.getScaledWidth() * 8, 0, 0, mask.getScaledHeight() * 8, 100, 400);
           cb.setRGBColorFill(0, 0, 255);
           cb.addImage(mask, mask.getScaledWidth() * 8, 0, 0, mask.getScaledHeight() * 8, 100, 350);
           document.close();
       }
       catch (Exception de) {
           de.printStackTrace();
       }
   }