Before now I have had a scale for each image loaded that would scale the coordinate grid in the render method, but it occurred to me that this could be a drain of cpu power, so I was wondering how to save a new resized version of a particular image at runtime. TY for any help!
Scaling is free if you’re using OpenGL (which you should be if you’re making a game).
If you’re using Java2D tough, you need to do some Graphics2D / Graphics operations:
// Takes some time! don't do this every frame!
public static BufferedImage createScaledVersion(int scalex, int scaley, BufferedImage source) {
BufferedImage destination = new BufferedImage(source.getWidth() * scalex, source.getHeight() * scaley, BufferedImage.TYPE_INT_ARGB);
Graphics g = destination.getGraphics(); // <- might be called getDrawGraphics() or somehow...
g.drawImage(source, 0, 0, destination.getWidth(), destination.getHeight(), null);
g.dispose();
return destination;
}
Not sure if it works or even compiles. But it should give you an idea!