本文整理匯總了Java中com.lowagie.text.Image.setImageMask方法的典型用法代碼示例。如果您正苦於以下問題:Java Image.setImageMask方法的具體用法?Java Image.setImageMask怎麽用?Java Image.setImageMask使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.lowagie.text.Image
的用法示例。
在下文中一共展示了Image.setImageMask方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import com.lowagie.text.Image; //導入方法依賴的package包/類
/**
* 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();
}
示例2: main
import com.lowagie.text.Image; //導入方法依賴的package包/類
/**
* 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();
}
}