简体   繁体   English

Java swing 如何使用4个点将图像绘制为四边形

[英]Java swing how to draw an image as a quadrilateral by using 4 points

I want to draw an image as a quadrilateral by using the points of the 4 corners as parameters.我想通过使用 4 个角的点作为参数将图像绘制为四边形。 Does Java have anything already built in for that? Java 是否已经为此内置了任何东西? I've seen a similar post but the solution given did not seem to do what I want.我看过类似的帖子,但给出的解决方案似乎没有达到我想要的效果。 The function call would look like this: function 调用如下所示:

wall.drawTexture(Point topLeft, Point topRight, Point bottomLeft, Point bottomRight);

My wall class already contains an attribute " BufferedImage texture".我的墙 class 已经包含一个属性“ BufferedImage纹理”。

在此处输入图像描述

Context: I'm doing a raycaster engine.背景:我正在做一个光线投射引擎。 I can split my image into smaller columns to correspond to my pixel columns on the 3D view but the texture integrity isn't very high.我可以将图像拆分为较小的列,以对应于 3D 视图上的像素列,但纹理完整性不是很高。 I thought by only using the first and last ray to hit the same wall face and convert to a parallelogram instead would solve my problem.我认为只使用第一条和最后一条光线照射同一个墙面并转换为平行四边形就可以解决我的问题。 It would also probably be faster than drawing column by column.它也可能比逐列绘制更快。

You could use drawLine.你可以使用drawLine。 Something where it draws a line between 1-2, 1-3, 4-2, 4-3.它在 1-2、1-3、4-2、4-3 之间划出一条线。

All I can suggest is that you consider the following:我只能建议您考虑以下几点:

paintComponent(Graphics g) {
     super.paintComponent(g);

    Graphics2D g2d = (Graphics2D) g;
    // Rendering hints can visually smooth out the graphics with
    // anti aliasing.
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
}

Other possibilities would be looking at the AffineTransform and related classes where you can manipulate various aspects of a graphics context (eg shearing, blurring, etc).其他可能性是查看AffineTransform和相关类,您可以在其中操作图形上下文的各个方面(例如剪切、模糊等)。

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

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