完全超出 JPanel 的范围

Drawing completely out of the range of a JPanel

在 Swing 中,如果我要使用 Graphics2D drawImage 方法在坐标处绘制图像,以便在可见面板中根本看不到它,例如 100 x 100 面板,在 -200、-200 处绘制 100 x 100 图像, 这是否会影响渲染时间,就像它在面板范围内并绘制到屏幕上一样?

或者有大量的语句来检查面板范围内是否有东西会更好,如果不在,则不绘制它?

这适用于有大量图像围绕面板坐标移动并且有些可能会离开面板范围的游戏。

干杯

Graphics context specifies that "All rendering operations modify only pixels which lie within the area bounded by the current clip," so no additional checks are typically required. See Painting in AWT and Swing 了解更多详情。

作为一个具体示例,MapPanel 继续渲染随着模拟的发展而离开网格的车辆。单击流浪出租车的 重置 按钮可将其重新显示。