【问题标题】:Better performance for Java Canvas Buffered imagesJava Canvas 缓冲图像的更好性能
【发布时间】:2014-05-31 14:08:22
【问题描述】:

我正在使用 Java Canvas 并且有一个绘图方法,该方法每秒调用大约 20 次。它遍历图像数组并根据窗口大小绘制它们的 scaledInstance:

g.drawImage(img.getScaledInstance(
                (short)Math.round(rect.width * yVector),
                (short)Math.round(rect.height * yVector),
                Image.SCALE_SMOOTH),
        (short)Math.round(rect.x * xVector),
        (short)Math.round(rect.y * yVector), null);

性能真的很差。我正在使用缓冲区策略,这就是声明 BufferedImage 图像的方式:

try {
    image = ImageIO.read(new File("resources/drawable/" + src));
    img = (BufferedImage)image.getImage();
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

【问题讨论】:

    标签: java canvas buffer bufferstrategy


    【解决方案1】:

    性能问题来自getScaledInstance。它以 20 次/秒的速度缩放图像,性能不佳。我们的应用程序现在具有固定的位置和大小,但以非常稳定的高 fps 速率运行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-14
      • 2013-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-28
      • 2013-10-03
      相关资源
      最近更新 更多