本文整理汇总了Java中com.lowagie.text.Image.scaleToFit方法的典型用法代码示例。如果您正苦于以下问题:Java Image.scaleToFit方法的具体用法?Java Image.scaleToFit怎么用?Java Image.scaleToFit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.lowagie.text.Image
的用法示例。
在下文中一共展示了Image.scaleToFit方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: printImage
import com.lowagie.text.Image; //导入方法依赖的package包/类
/** Print an iText image */
private void printImage(Image image, PdfContentByte cb, float x1, float y1, float x2, float y2, int alignment, int fitMethod, float rotate)
throws DocumentException {
if(image!=null) {
float boxWidth = Math.abs(x2-x1)+1;
float boxHeight = Math.abs(y2-y1)+1;
log.debug("Print Image (Size w="+image.getPlainWidth()+",h="+image.getPlainHeight()+") wthin BOX (w="+boxWidth+",h="+boxHeight+") FitMethod = "+fitMethod);
// Clip the image based on the bounding box
if(fitMethod==FIT_METHOD_CLIP) {
if( (boxWidth < image.getPlainWidth()) || (boxHeight < image.getPlainHeight()) ) {
// @TODO - Clip image
log.warn("IMAGE CLIPPING REQUIRED, but not implemented - default to 'SCALE'...");
fitMethod=FIT_METHOD_SCALE;
}
}
// Stretch/shrink both the X/Y to fit the bounding box
if(fitMethod==FIT_METHOD_FILL) {
log.debug("Scale image to fill box");
image.scaleToFit(x2-x1, y2-y1);
}
// Stretch/shrink preserving the aspect ratio to fit the bounding box
if(fitMethod==FIT_METHOD_SCALE) {
float multipler = Math.min(boxWidth / image.getPlainWidth(), boxHeight /image.getPlainHeight());
log.debug("Need to scale image by " + (Math.floor(multipler*10000)/100) + "%");
image.scalePercent(multipler*100);
}
log.debug("Print image at (" + x1 + "," + y1 +")");
image.setAbsolutePosition(x1,y1);
image.setRotationDegrees(rotate);
cb.addImage(image);
//Phrase text = new Phrase(new Chunk(image, 0, 0));
//ColumnText ct = new ColumnText(cb);
//ct.setSimpleColumn(text, x1, y1, x2, y2, 10, alignment);
//ct.go();
}
}
示例2: addImage
import com.lowagie.text.Image; //导入方法依赖的package包/类
/**
* Adds an image to this Cell.
*
* @param i the image to add
* @param left the left border
* @param right the right border
* @param extraHeight extra height to add above image
* @param alignment horizontal alignment (constant from Element class)
* @return the height of the image
*/
private float addImage(Image i, float left, float right, float extraHeight, int alignment) {
Image image = Image.getInstance(i);
if (image.getScaledWidth() > right - left) {
image.scaleToFit(right - left, Float.MAX_VALUE);
}
flushCurrentLine();
if (line == null) {
line = new PdfLine(left, right, alignment, leading);
}
PdfLine imageLine = line;
// left and right in chunk is relative to the start of the line
right = right - left;
left = 0f;
if ((image.getAlignment() & Image.RIGHT) == Image.RIGHT) {
left = right - image.getScaledWidth();
} else if ((image.getAlignment() & Image.MIDDLE) == Image.MIDDLE) {
left = left + ((right - left - image.getScaledWidth()) / 2f);
}
Chunk imageChunk = new Chunk(image, left, 0);
imageLine.add(new PdfChunk(imageChunk, null));
addLine(imageLine);
return imageLine.height();
}
示例3: processImageRetainShape
import com.lowagie.text.Image; //导入方法依赖的package包/类
private InternalImageProcessorResult processImageRetainShape(String rendererId, DataRenderable renderer) throws JRException
{
Image image = null;
if (printImage.isUsingCache() && loadedImagesMap.containsKey(rendererId))
{
image = loadedImagesMap.get(rendererId);
}
else
{
try
{
image = Image.getInstance(renderer.getData(jasperReportsContext));
imageTesterPdfContentByte.addImage(image, 10, 0, 0, 10, 0, 0);
}
catch (Exception e)
{
throw new JRException(e);
}
if (printImage.isUsingCache())
{
loadedImagesMap.put(rendererId, image);
}
}
image.scaleToFit(availableImageWidth, availableImageHeight);
int xoffset = (int)(ImageUtil.getXAlignFactor(printImage) * (availableImageWidth - image.getPlainWidth()));
int yoffset = (int)(ImageUtil.getYAlignFactor(printImage) * (availableImageHeight - image.getPlainHeight()));
xoffset = (xoffset < 0 ? 0 : xoffset);
yoffset = (yoffset < 0 ? 0 : yoffset);
return
new InternalImageProcessorResult(
new Chunk(image, 0, 0),
image.getScaledWidth(),
image.getScaledHeight(),
xoffset,
yoffset
);
}
示例4: createImage
import com.lowagie.text.Image; //导入方法依赖的package包/类
/**
*
* @param imageAsBytes
* The image as byte array.
* @param width
* Width.
* @param height
* Height,
* @return The image.
* @throws BadElementException
* exception.
* @throws IOException
* exception.
*/
public static Element createImage(byte[] imageAsBytes, float width, float height)
throws BadElementException, IOException {
Image image = Image.getInstance(imageAsBytes);
image.scaleToFit(width, height);
return image;
}