Java - Resize images upon class instantiation

Posted by Tyler J Fisher on Game Development See other posts from Game Development or by Tyler J Fisher
Published on 2012-03-21T06:02:24Z Indexed on 2012/03/21 11:39 UTC
Read the original article Hit count: 505

Filed under:
|

Hey StackExchange GameDev community, I'm attempting to:

  • Resize series of sprites upon instantiation of the class they're located in (x2)

I've attempted to use the following code to resize the images, however my attempts have been unsuccessful. I have been unable to write an implementation that is even compilable, so no error codes yet.

    wLeft.getScaledInstance(wLeft.getWidth()*2, wLeft.getHeight()*2, Image.SCALE_FAST);

I've heard that Graphics2D is the best option.

Any suggestions? I think I'm probably best off loading the images into a Java project, resizing the images then outputting them to a new directory so as not to have to resize each sprite upon class instantiation. What do you think?

Photoshopping each individual sprite is out of the question, unless I used a macro.

Code:

package game;

//Import
import java.awt.Image;
import javax.swing.ImageIcon;

public class Mario extends Human {
    Image wLeft = new ImageIcon("sprites\\mario\\wLeft.PNG").getImage();

 //Constructor
    public Mario(){
        super("Mario", 50);
        wLeft.getScaledInstance(wLeft.getWidth()*2, wLeft.getHeight()*2, Image.SCALE_FAST);
    }

Thanks! Note: not homework, just thought Mario would be a good, overused starting point in game dev.

© Game Development or respective owner

Related posts about java

Related posts about image