在屏幕外绘制二维图形?然后将其一部分并显示在屏幕上

发布于 2024-12-12 11:29:20 字数 69 浏览 1 评论 0原文

我想在屏幕外绘制一个 Graphics2D 组件,然后取出其中的一部分并在屏幕上显示实时更新图像,因此缓冲图像需要很长时间。

i want to paint a graphics2D component off screen then take part of it and show on screen for a live updating image, so buffered image takes to long.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜夜流光相皎洁 2024-12-19 11:29:20

在 JPanel 中使用 setDoubleBuffered( true );
这会在屏幕外进行绘制,当它完成屏幕外绘制时,它将显示在 JPanel 上。
使用此功能时,您将不再获得黑色/未上漆的框架。

Use setDoubleBuffered( true ); in your JPanel.
That pains it offscreen, and when it's done painting offscreen, it will be shown on the JPanel.
You won't get black/unpainted frames anymore when using this.

就是爱搞怪 2024-12-19 11:29:20

查看 BufferCapability (和相关类),以及MultipleBuffering 的图形概念。

此外,速度慢的可能不是 BufferedImage,而是渲染管道如何利用(或不利用)可用的硬件加速。

如果您偶然正在构建一个游戏或其他一些需要利用 Java 中的硬件加速进行高速渲染的应用程序,那么您最好从一个为您处理这些细节的库开始,例如 Slick2D

Slick2D 的其他真正优点之一是它是跨平台的,并且会为您处理渲染性能细节,因为实际的渲染管道会在平台、JVM 版本之间发生变化,和硬件(取决于 Java 公开的可用功能),这只是您不想自己弄清楚的大量细节和试验/错误。大量的时间浪费。

LWGJL(实现 Slick2D 图形性能的库)基本上完全避开了 Java2D,以实现这一点。如果您想深入挖掘,那里有一些有趣的读物。

Look into BufferCapabilities (and related classes), as well as the graphics concept of MultipleBuffering.

Also, it's probably not BufferedImage that is slow, it's how the rendering pipeline utilizes (or doesn't utilize) the available hardware acceleration.

If, by chance, you're building a game, or some other app that needs high-speed rendering that takes advantage of hardware acceleration in Java, you'd be well served to start with a library that takes care of these details for you, like Slick2D.

One of the other really nice things about Slick2D is that it's cross platform, and takes care of the rendering performance details for you, because the actual rendering pipeline changes between platforms, JVM versions, and hardware (depending on the available features that are exposed to Java), and that's just a lot of details and trial/error you don't want to figure out on your own. BIG time sink.

LWGJL (the library that enables Slick2D's graphics performance) basically completely sidesteps Java2D, to enable this. There's some interesting reading in there if you want to dig deep.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文