小编Sco*_*ott的帖子

Java2D:BufferedImage在Ubuntu上没有加速

我们目前正在使用Java2D API开发Java游戏,并且在Ubuntu环境中运行它时会遇到一些奇怪的性能问题.

我们的帧速率从Windows和Mac系统上的平均62fps下降到Ubuntu上的大约10fps.经过几个小时的调试和测试各种JVM标志后,似乎是使用位掩码的BufferedImages在Ubuntu下没有加速,因为

System.out.println(img.getCapabilities(config).isAccelerated());
Run Code Online (Sandbox Code Playgroud)

打印错误.

目前我们正在加载我们的图像

img = ImageIO.read(url);
Run Code Online (Sandbox Code Playgroud)

然后使用以下方法创建与设备兼容的BufferedImage:

private static BufferedImage createCompatibleImage(BufferedImage img) {

    // Get default graphics device
    GraphicsDeviceService graphicsDevice = ServiceProvider
            .getService(GraphicsDeviceService.class);
    GraphicsConfiguration config = graphicsDevice
            .getGraphicsConfiguration();

    // Get desired transparency mode
    int transparency = img.getColorModel().hasAlpha() ? Transparency.BITMASK
            : Transparency.OPAQUE;

    // Create device compatible buffered image
    BufferedImage ret = config.createCompatibleImage(img.getWidth(),
            img.getHeight(), transparency);

    // Draw old image onto new compatible image
    Graphics2D graphics = ret.createGraphics();
    graphics.drawImage(img, 0, 0, null);
    graphics.dispose();

    // Return compatible image
    return ret;
} …
Run Code Online (Sandbox Code Playgroud)

java ubuntu performance java-2d

5
推荐指数
1
解决办法
883
查看次数

标签 统计

java ×1

java-2d ×1

performance ×1

ubuntu ×1