當前位置: 首頁>>代碼示例>>Java>>正文


Java Image.scaleToFit方法代碼示例

本文整理匯總了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();
    }
}
 
開發者ID:jaffa-projects,項目名稱:jaffa-framework,代碼行數:38,代碼來源:FormPrintEngineIText.java

示例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();
}
 
開發者ID:albfernandez,項目名稱:itext2,代碼行數:37,代碼來源:PdfCell.java

示例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
			);
}
 
開發者ID:TIBCOSoftware,項目名稱:jasperreports,代碼行數:44,代碼來源:JRPdfExporter.java

示例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;
}
 
開發者ID:Communote,項目名稱:communote-server,代碼行數:21,代碼來源:RtfElementFactory.java


注:本文中的com.lowagie.text.Image.scaleToFit方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。