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


Java Image.getScaledWidth方法代碼示例

本文整理匯總了Java中com.itextpdf.text.Image.getScaledWidth方法的典型用法代碼示例。如果您正苦於以下問題:Java Image.getScaledWidth方法的具體用法?Java Image.getScaledWidth怎麽用?Java Image.getScaledWidth使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.itextpdf.text.Image的用法示例。


在下文中一共展示了Image.getScaledWidth方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: savePageAsPdf

import com.itextpdf.text.Image; //導入方法依賴的package包/類
public String savePageAsPdf(boolean scaled) throws IOException, DocumentException
{
	String pdfName = "";

	// Define test screenshot root
	String test = "";
	if (TestNamingUtil.isTestNameRegistered()) {
		test = TestNamingUtil.getTestNameByThread();
	} else {
		test = "undefined";
	}
	
	File testRootDir = ReportContext.getTestDir();
	File artifactsFolder = ReportContext.getArtifactsFolder();

	String fileID = test.replaceAll("\\W+", "_") + "-" + System.currentTimeMillis();
	pdfName = fileID + ".pdf";

	String fullPdfPath = artifactsFolder.getAbsolutePath() + "/" + pdfName;
	// TODO: test this implementation and change back to capture if necessary
	Image image = Image.getInstance(testRootDir.getAbsolutePath() + "/" + Screenshot.captureFailure(driver, ""));
	Document document = null;
	if (scaled)
	{
		document = new Document(PageSize.A4, 10, 10, 10, 10);
		if (image.getHeight() > (document.getPageSize().getHeight() - 20)
				|| image.getScaledWidth() > (document.getPageSize().getWidth() - 20))
		{
			image.scaleToFit(document.getPageSize().getWidth() - 20, document.getPageSize().getHeight() - 20);
		}
	} else
	{
		document = new Document(new RectangleReadOnly(image.getScaledWidth(), image.getScaledHeight()));
	}
	PdfWriter.getInstance(document, new FileOutputStream(fullPdfPath));
	document.open();
	document.add(image);
	document.close();
	return fullPdfPath;
}
 
開發者ID:qaprosoft,項目名稱:carina,代碼行數:41,代碼來源:AbstractPage.java

示例2: cropImageToMeetRatio

import com.itextpdf.text.Image; //導入方法依賴的package包/類
public static Image cropImageToMeetRatio(PdfWriter pdfWriter, Image image, float heightToWidthRatio) throws
        DocumentException {
    float imageWidth = image.getScaledWidth();
    float imageHeight = image.getScaledHeight();
    float imageDesiredWidth = imageHeight / heightToWidthRatio;
    float widthToCut = imageWidth - imageDesiredWidth; //TODO: Sprawdzic czy liczba nie jest ujemna. Jeżeli tak to przycinać wysokość zamiast szerokości

    return cropImage(pdfWriter, image, new CropRectangle(widthToCut / 2, widthToCut / 2, 0, 0));
}
 
開發者ID:lenrok258,項目名稱:MountainQuest-PL,代碼行數:10,代碼來源:ImageUtils.java

示例3: cropImage

import com.itextpdf.text.Image; //導入方法依賴的package包/類
private static Image cropImage(PdfWriter pdfWriter, Image image, CropRectangle cropRectangle) throws
        DocumentException {
    float width = image.getScaledWidth();
    float height = image.getScaledHeight();
    PdfTemplate template = pdfWriter.getDirectContent().createTemplate(
            width - cropRectangle.leftReduction - cropRectangle.rightReduction,
            height - cropRectangle.topReduction - cropRectangle.bottomReduction);
    template.addImage(image,
            width, 0, 0,
            height, -cropRectangle.leftReduction, -cropRectangle.bottomReduction);
    return Image.getInstance(template);
}
 
開發者ID:lenrok258,項目名稱:MountainQuest-PL,代碼行數:13,代碼來源:ImageUtils.java

示例4: cropMapImage

import com.itextpdf.text.Image; //導入方法依賴的package包/類
private Image cropMapImage(Image image) throws DocumentException {
    float width = image.getScaledWidth();
    float height = image.getScaledHeight();
    float footerReductionPercentage = GOOGLE_MAPS_FOOTER_HEIGHT / height;
    int widthReduction = (int) (width * footerReductionPercentage);
    CropRectangle cropRectangle = new CropRectangle(0, widthReduction, 0, GOOGLE_MAPS_FOOTER_HEIGHT);

    return ImageUtils.cropImageToRectangle(pdfWriter, image, cropRectangle);
}
 
開發者ID:lenrok258,項目名稱:MountainQuest-PL,代碼行數:10,代碼來源:DataPageGenerator.java


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