Fastest way to drawImage()?

Hello!
I’m making a platform game engine for a school project, but it isn’t quite fast enough. I had the idea of rendering the whole display to a single image that returns when you call a method in my engine class, and indeed, that is sufficiently fast (from start to end the method takes ~15ms).

The bottleneck seems to be when I actually draw the rendered image to the screen, when the time it takes doubles or even triples. I think that there must be a faster way to put an image on the screen, but I’ve tried and tried to no avail. Here’s how my main code looks (leaving out the window listener code and other stuff that doesn’t seem to be related to the problem):

public class Main {
   
    public static void main(String[] args) {
        JFrame frame = new JFrame("test");
        
        Canvas canvas= new Canvas();
        canvas.setSize(640,480);
        frame.add(canvas);
	frame.pack();
        frame.setResizable(false);
	frame.setVisible(true);
        
        Graphics frameGraphics=canvas.getGraphics();
        
        Level levelOne= new Level ("level.png","tiles.png","tilecolors.png"); //creates a new instance of my Level class. Just disregard this.
        
        Image background=levelOne.getBackground();
        while(true) {
            frameGraphics.drawImage(levelOne.getImage(), 0, 0,null); //levelOne.getImage() is the method that returns the current screen Image
        }
    }

}

Anyone know how to make this faster? I appreciate any hints or help, but please keep in mind that I’m very new to Java and OOP (with a couple of years experience in C).

Transparent is fine, but if your PNGs are translucent, it will/can slow down image rendering onto the screen.

I tend to use GIF or JPG if I can as to improve performance.

The actual image files passed to the Level constructor are never drawn, but are loaded into BufferedImages where the pixel ARGB integer values are read sequentially to render the image… The Image that is actually drawn to the canvas is not transparent or transculent.

Just saving the returned Image from levelOne.getImage() takes around 15ms, but drawing it to the screen takes around 60ms, so I’d like to know if there’s any way to speed that up.

Thanks anyway! I think that you saved me a lot of time in the future by telling me that transculent images are slower to render :slight_smile:

What do you mean by this:

Could you show us some code?

lg Clemens

One thing: do not render directly to the screen (or do drawImage to the screen). Use java.awt.BufferStrategy API for
double-buffering.

And, as others said, it would be easier to advise further if we could see your image loading/setting up code.

Dmitri