Slow Java2D Drawing on Integrated Graphics

后端 未结 1 1319
庸人自扰
庸人自扰 2021-01-26 08:57

I\'m working on a simple 2D game, rendering via the Java2D API. I\'ve noticed that when I try to draw on integrated graphics card the performance crashes.

I\'ve tested t

相关标签:
1条回答
  • 2021-01-26 09:41

    This is an example of converting an image to a compatiable image...not an answer in of itself

    This is some of the library code that I use...

    public static BufferedImage createCompatibleImage(BufferedImage image) {
        BufferedImage target = createCompatibleImage(image, image.getWidth(), image.getHeight());
        Graphics2D g2d = target.createGraphics();
        g2d.drawImage(image, 0, 0, null);
        g2d.dispose();
        return target;
    }
    
    public static BufferedImage createCompatibleImage(BufferedImage image,
            int width, int height) {
        return getGraphicsConfiguration().createCompatibleImage(width, height, image.getTransparency());
    }
    
    public static GraphicsConfiguration getGraphicsConfiguration() {
        return GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
    }
    

    I would do something like...

    I = createCompatibleImage(ImageIO.read(new File(currentFolder+imgPath)));
    imgMap.put(imgIdentifier, I);
    
    0 讨论(0)
提交回复
热议问题