我目前使用itextPdf庫來生成PDF文件。Image in mode mosaic in PdfPCell
對於設置我用itextpdf.com的this solution圖像0現在我想成立一個小尺寸的圖像作爲PdfPCell在模式馬賽克背景:如果電池有3×IMAGESIZE,在PDF我將我的圖像重複單元格中的3次
我該怎麼做?
這是我的例子
public class ImageBackgroundEvent implements PdfPCellEvent {
protected Image image;
protected boolean mosaic;
protected boolean full;
public ImageBackgroundEvent(Image image, boolean mosaic, boolean full) {
this.image = image;
this.mosaic = mosaic;
this.full = full;
}
public void cellLayout(PdfPCell cell, Rectangle position,
PdfContentByte[] canvases) {
try {
PdfContentByte cb = canvases[PdfPTable.BACKGROUNDCANVAS];
if(full){
cell.setImage(image);
}
else if(mosaic){
float imgWidth = image.getWidth();
float imgHeight = image.getHeight();
float cellWidth = cell.getWidth();
float cellHeight = cell.getHeight();
if(imgHeight < cellHeight && imgWidth < cellWidth){
PdfPatternPainter pattern = cb.createPattern(imgWidth, imgHeight);
pattern.addImage(image);
pattern.setPatternMatrix(-0.5f, 0f, 0f, 0.5f, 0f, 0f);
cb.setPatternFill(pattern);
//cb.ellipse(180, 408, 450, 534);
cb.fillStroke();
} else{
image.scaleAbsolute(position);
image.setAbsolutePosition(position.getLeft(), position.getBottom());
cb.addImage(image);
}
} else{
image.scaleAbsolute(position);
image.setAbsolutePosition(position.getLeft(), position.getBottom());
cb.addImage(image);
}
} catch (DocumentException e) {
throw new ExceptionConverter(e);
}
}
}
是的,這是可能的。 –
布魯諾,感謝您的回覆。我編輯了我的問題。我不知道如何應用馬賽克過程。 – Valeriane
我會創建一個圖案顏色使用圖像作爲瓷磚模式中的一個瓷磚。然後,我會將該圖案顏色作爲背景顏色應用。 –