当前位置: 首页>>代码示例>>Java>>正文


Java Image.getScaledWidth方法代码示例

本文整理汇总了Java中com.lowagie.text.Image.getScaledWidth方法的典型用法代码示例。如果您正苦于以下问题:Java Image.getScaledWidth方法的具体用法?Java Image.getScaledWidth怎么用?Java Image.getScaledWidth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.lowagie.text.Image的用法示例。


在下文中一共展示了Image.getScaledWidth方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: add

import com.lowagie.text.Image; //导入方法依赖的package包/类
/**
 * Adds an image to the document.
 * @param image the <CODE>Image</CODE> to add
 * @throws PdfException on error
 * @throws DocumentException on error
 */

protected void add(Image image) throws PdfException, DocumentException {

    if (image.hasAbsoluteY()) {
        graphics.addImage(image);
        pageEmpty = false;
        return;
    }

    // if there isn't enough room for the image on this page, save it for the next page
    if (currentHeight != 0 && indentTop() - currentHeight - image.getScaledHeight() < indentBottom()) {
        if (!strictImageSequence && imageWait == null) {
            imageWait = image;
            return;
        }
        newPage();
        if (currentHeight != 0 && indentTop() - currentHeight - image.getScaledHeight() < indentBottom()) {
            imageWait = image;
            return;
        }
    }
    pageEmpty = false;
    // avoid endless loops
    if (image == imageWait)
        imageWait = null;
    boolean textwrap = (image.getAlignment() & Image.TEXTWRAP) == Image.TEXTWRAP
    && !((image.getAlignment() & Image.MIDDLE) == Image.MIDDLE);
    boolean underlying = (image.getAlignment() & Image.UNDERLYING) == Image.UNDERLYING;
    float diff = leading / 2;
    if (textwrap) {
        diff += leading;
    }
    float lowerleft = indentTop() - currentHeight - image.getScaledHeight() -diff;
    float mt[] = image.matrix();
    float startPosition = indentLeft() - mt[4];
    if ((image.getAlignment() & Image.RIGHT) == Image.RIGHT) startPosition = indentRight() - image.getScaledWidth() - mt[4];
    if ((image.getAlignment() & Image.MIDDLE) == Image.MIDDLE) startPosition = indentLeft() + ((indentRight() - indentLeft() - image.getScaledWidth()) / 2) - mt[4];
    if (image.hasAbsoluteX()) startPosition = image.getAbsoluteX();
    if (textwrap) {
        if (imageEnd < 0 || imageEnd < currentHeight + image.getScaledHeight() + diff) {
            imageEnd = currentHeight + image.getScaledHeight() + diff;
        }
        if ((image.getAlignment() & Image.RIGHT) == Image.RIGHT) {
        	// indentation suggested by Pelikan Stephan
        	indentation.imageIndentRight += image.getScaledWidth() + image.getIndentationLeft();
        }
        else {
        	// indentation suggested by Pelikan Stephan
        	indentation.imageIndentLeft += image.getScaledWidth() + image.getIndentationRight();
        }
    }
    else {
    	if ((image.getAlignment() & Image.RIGHT) == Image.RIGHT) startPosition -= image.getIndentationRight();
    	else if ((image.getAlignment() & Image.MIDDLE) == Image.MIDDLE) startPosition += image.getIndentationLeft() - image.getIndentationRight();
    	else startPosition += image.getIndentationLeft();
    }
    graphics.addImage(image, mt[0], mt[1], mt[2], mt[3], startPosition, lowerleft - mt[5]);
    if (!(textwrap || underlying)) {
        currentHeight += image.getScaledHeight() + diff;
        flushLines();
        text.moveText(0, - (image.getScaledHeight() + diff));
        newLine();
    }
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:71,代码来源:PdfDocument.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: main

import com.lowagie.text.Image; //导入方法依赖的package包/类
/**
 * Combines 2 tiff-files into 1 PDF (similar to tiffmesh).
 * 
 * @param args
 *            [0] the file with the odd pages [1] the file with the even
 *            pages [2] the resulting file
 */
public void main(String... args) throws Exception {
	if (args.length < 3) {
		System.err.println("OddEven needs 3 Arguments.");
		System.out
				.println("Usage: com.lowagie.examples.objects.images.tiff.OddEven odd_file.tif even_file.tif combined_file.pdf");
		return;
	}
	RandomAccessFileOrArray odd = new RandomAccessFileOrArray(args[0]);
	RandomAccessFileOrArray even = new RandomAccessFileOrArray(args[1]);
	Image img = TiffImage.getTiffImage(odd, 1);
	Document document = new Document(new Rectangle(img.getScaledWidth(), img.getScaledHeight()));
	PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(args[2]));
	document.open();
	PdfContentByte cb = writer.getDirectContent();
	int count = Math.max(TiffImage.getNumberOfPages(odd), TiffImage.getNumberOfPages(even));
	for (int c = 0; c < count; ++c) {

		Image imgOdd = TiffImage.getTiffImage(odd, c + 1);
		Image imgEven = TiffImage.getTiffImage(even, count - c);
		document.setPageSize(new Rectangle(imgOdd.getScaledWidth(), imgOdd.getScaledHeight()));
		document.newPage();
		imgOdd.setAbsolutePosition(0, 0);
		cb.addImage(imgOdd);
		document.setPageSize(new Rectangle(imgEven.getScaledWidth(), imgEven.getScaledHeight()));
		document.newPage();
		imgEven.setAbsolutePosition(0, 0);
		cb.addImage(imgEven);

	}
	odd.close();
	even.close();
	document.close();

}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:42,代码来源:OddEvenTest.java

示例4: processImageFillFrame

import com.lowagie.text.Image; //导入方法依赖的package包/类
private InternalImageProcessorResult processImageFillFrame(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.scaleAbsolute(availableImageWidth, availableImageHeight);
	
	return 
		new InternalImageProcessorResult(
			new Chunk(image, 0, 0), 
			image.getScaledWidth(), 
			image.getScaledHeight(),
			0,
			0
			);
}
 
开发者ID:TIBCOSoftware,项目名称:jasperreports,代码行数:38,代码来源:JRPdfExporter.java

示例5: getMaxHeight

import com.lowagie.text.Image; //导入方法依赖的package包/类
/**
 * Returns the height of the cell.
 * @return	the height of the cell
 * @since	3.0.0
 */
public float getMaxHeight() {
	boolean pivoted = (getRotation() == 90 || getRotation() == 270);
	Image img = getImage();
	if (img != null) {
		img.scalePercent(100);
		float refWidth = pivoted ? img.getScaledHeight() : img.getScaledWidth();
		float scale = (getRight() - getEffectivePaddingRight()
                   - getEffectivePaddingLeft() - getLeft()) / refWidth;
		img.scalePercent(scale * 100);
		float refHeight = pivoted ? img.getScaledWidth() : img.getScaledHeight();
		setBottom(getTop() - getEffectivePaddingTop() - getEffectivePaddingBottom() - refHeight);
	}
	else {
		if ((pivoted && hasFixedHeight()) || getColumn() == null)
			setBottom(getTop() - getFixedHeight());
		else {
			ColumnText ct = ColumnText.duplicate(getColumn());
			float right, top, left, bottom;
			if (pivoted) {
				right = PdfPRow.RIGHT_LIMIT;
				top = getRight() - getEffectivePaddingRight();
				left = 0;
				bottom = getLeft() + getEffectivePaddingLeft();
			}
			else {
				right = isNoWrap() ? PdfPRow.RIGHT_LIMIT : getRight() - getEffectivePaddingRight();
				top = getTop() - getEffectivePaddingTop();
				left = getLeft() + getEffectivePaddingLeft();
				bottom = hasFixedHeight() ? getTop() + getEffectivePaddingBottom() - getFixedHeight() : PdfPRow.BOTTOM_LIMIT;
			}
			PdfPRow.setColumn(ct, left, bottom, right, top);
			try {
				ct.go(true);
			} catch (DocumentException e) {
				throw new ExceptionConverter(e);
			}
			if (pivoted)
				setBottom(getTop() - getEffectivePaddingTop() - getEffectivePaddingBottom() - ct.getFilledWidth());
			else {
				float yLine = ct.getYLine();
				if (isUseDescender())
					yLine += ct.getDescender();
				setBottom(yLine - getEffectivePaddingBottom());
			}
		}
	}
	float height = getHeight();
	if (hasFixedHeight())
		height = getFixedHeight();
	else if (height < getMinimumHeight())
		height = getMinimumHeight();
	return height;
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:59,代码来源:PdfPCell.java

示例6: processImageClip

import com.lowagie.text.Image; //导入方法依赖的package包/类
private InternalImageProcessorResult processImageClip(Graphics2DRenderable renderer) throws JRException, IOException, BadElementException
{
	int normalWidth = availableImageWidth;
	int normalHeight = availableImageHeight;

	Dimension2D dimension = 
		renderer instanceof DimensionRenderable 
		? ((DimensionRenderable)renderer).getDimension(jasperReportsContext) 
		: null;
	if (dimension != null)
	{
		normalWidth = (int)dimension.getWidth();
		normalHeight = (int)dimension.getHeight();
	}

	int xoffset = (int)(ImageUtil.getXAlignFactor(printImage) * (availableImageWidth - normalWidth));
	int yoffset = (int)(ImageUtil.getYAlignFactor(printImage) * (availableImageHeight - normalHeight));

	int minWidth = Math.min(normalWidth, availableImageWidth);
	int minHeight = Math.min(normalHeight, availableImageHeight);

	BufferedImage bi =
		new BufferedImage(minWidth, minHeight, BufferedImage.TYPE_INT_ARGB);

	Graphics2D g = bi.createGraphics();
	try
	{
		if (printImage.getModeValue() == ModeEnum.OPAQUE)
		{
			g.setColor(printImage.getBackcolor());
			g.fillRect(0, 0, minWidth, minHeight);
		}
		renderer.render(
			jasperReportsContext,
			g,
			new java.awt.Rectangle(
				(xoffset > 0 ? 0 : xoffset),
				(yoffset > 0 ? 0 : yoffset),
				normalWidth,
				normalHeight
				)
			);
	}
	finally
	{
		g.dispose();
	}

	xoffset = (xoffset < 0 ? 0 : xoffset);
	yoffset = (yoffset < 0 ? 0 : yoffset);

	//awtImage = bi.getSubimage(0, 0, minWidth, minHeight);

	//image = com.lowagie.text.Image.getInstance(awtImage, printImage.getBackcolor());
	Image image = Image.getInstance(bi, null);
	
	return 
		new InternalImageProcessorResult(
			new Chunk(image, 0, 0), 
			image.getScaledWidth(), 
			image.getScaledHeight(),
			xoffset,
			yoffset
			);
}
 
开发者ID:TIBCOSoftware,项目名称:jasperreports,代码行数:66,代码来源:JRPdfExporter.java

示例7: 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


注:本文中的com.lowagie.text.Image.getScaledWidth方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。