简体   繁体   English

如何将PerspectiveTransform应用于图形对象或图像?

[英]How do i apply a PerspectiveTransform to graphics object or image?

I'm trying to draw a square image into a trapezoid using the Java Advanced Imaging API; 我正在尝试使用Java Advanced Imaging API将方形图像绘制成梯形; However after creating a PerspectiveTransform I am unsure how I would go about applying it to a graphics object or image. 然而,在创建PerspectiveTransform之后,我不确定如何将其应用于图形对象或图像。

When you apply a JAI operation, get RenderedOp , whichever operation (PerspectiveTransform, Scale...) as result. 当您应用JAI操作时,获取RenderedOp ,无论哪个操作(PerspectiveTransform,Scale ...)作为结果。 This represents the operation in a chain if you apply several operations to the same image, so the next operation is applied over the RenderedOp and so on. 如果您对同一图像应用多个操作,则表示链中的操作,因此下一个操作将应用于RenderedOp ,依此类推。 Finally, you need to draw it, so: 最后,你需要绘制它,所以:

1) Convert it to RenderedImage in order to apply all calculations to the final image. 1)将其转换为RenderedImage ,以便将所有计算应用于最终图像。 Use something like: 使用类似的东西:

new BufferedImage(renderedOp.getColorModel(), renderedOp.copyData(), false, null);

2) Draw the image onto a Graphics using something like: 2)使用以下内容将图像绘制到Graphics

Graphics2D graphics2D = (Graphics2D)graphics; // Convert the graphics received to Graphics2D to get more operations.
graphics2D.drawRenderedImage(renderedImage, new AffineTransform());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM