gpt4 book ai didi

java - itext 7.0.2 图像顺时针旋转

转载 作者:行者123 更新时间:2023-12-02 11:19:37 28 4
gpt4 key购买 nike

图像元素(com.itextpdf.layout.element.Image)支持逆时针旋转。是否可以对同一个图像进行顺时针旋转?

PdfPage page = iTextPdfDoc.getLastPage();
PdfCanvas pdfCanvas = new PdfCanvas(page.newContentStreamAfter(), page.getResources(), iTextPdfDoc);
Canvas canvas = new Canvas(pdfCanvas, iTextPdfDoc, page.getPageSize());
Image img = new Image(ImageDataFactory.create(path));
img.scaleAbsolute(525.58203, 737.0079)
img.setFixedPosition(30.785828, 34.66619)

// The following block of code does not affect the center point of rotation.
// I tried a lot of different values for rotation point. No change!
{
img.setProperty(Property.ROTATION_POINT_X, 30.785828);
img.setProperty(Property.ROTATION_POINT_Y, 34.66619);
}

img.setProperty(Property.ROTATION_ANGLE, Math.toRadians(90)); //img.setRotationAngle(Math.toRadians(90));
canvas.add(img);

更新:

这就是逆时针旋转 90 度的图像所发生的情况。 enter image description here

这就是逆时针使用 -90 或 270 度的图像所发生的情况。 enter image description here

最佳答案

关于:

img.setRotationAngle(Math.toRadians(270));

为什么要为只用一个函数就能完成的事情创建两个函数来使事情变得复杂?

(后面这句话是受到 Venkat Subramaniam 今天早上在大印度开发者峰会上发表的主题演讲的影响。主题演讲的标题是:“不要远离复杂性,快跑!”)

更新:

在您最初发表评论后(我也尝试使用 270。由于我不明白的原因,图像已顺时针旋转,但它位于 pdf 页面的底部下方。),我制作了这张图片:

enter image description here

在您的第二条评论中,您写道:您是对的!这意味着我必须再次设置位置,以便将图像显示到pdf页面中。如何移动图像,以便将其移动到页面底部上方?

这可能取决于您首先如何定位图像。您目前使用什么?您使用的是 setFixedPosition() 还是 setRelativePosition() 方法?或者您只是将图像添加到文档中而不定义位置?

关于java - itext 7.0.2 图像顺时针旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50027043/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com