If the class in which you call Graphics.drawImage(Image, int, int, int, int, ImageObserver) is ImageObserver using this , because the argument for ImageObserver will not work:
class MyClass { public void resizeImage() { Graphics g = getGraphicsObjectFromSomewhere();
If you are ImageObserver image that does not require ImageObserver (for example, BufferedImage , which already contains the image you want to resize), then you can simply pass null :
However, I'm going to add a small trial for the Thumbnailator image resizing library.
If all that is required is resizing the image, it can be performed as simply as the following code:
Thumbnails.of("path/to/image") .size(100, 100) .toFile("path/to/thumbnail");
The Thumbnailator is flexible enough to accept BufferedImage s, File s, and InputStream as input.
Having seen your editing, I would suggest changing the Hitter class so that it performs image resizing in the constructor.
Since you call the drawHitter method for each call from Applet.drawImage , the Applet.drawImage operation using Graphics.drawImage is called many times, even if hitterWidth and hitterHeight are hitterHeight for all purposes and purposes.
Resizing the Image advance, and drawing this previously drawHitter image in the drawHitter method will be more efficient.
coobird
source share