In your example, this is not an image that you are scaling, but you are setting a scaling transformation of the Graphics2D object that will apply to all operations performed in this graphics context.
If you want to scale the image, you have 2 options. Everything that I write below uses java.awt.Image , but since BufferedImage extends Image , all this applies to BufferedImage .
1. Image.getScaledInstance()
You can use the Image.getScaledInstance(int width, int height, int hints) method Image.getScaledInstance(int width, int height, int hints) . The third parameter ( hints ) indicates which scaling algorithm you want to use, which will affect the "quality" of the scaled image. Possible values:
SCALE_DEFAULT, SCALE_FAST, SCALE_SMOOTH, SCALE_REPLICATE, SCALE_AREA_AVERAGING
Try SCALE_AREA_AVERAGING and SCALE_SMOOTH for better images.
// Scaled 3 times: Image img2 = img.getScaledInstance(img.getWidth(null)*3, img.getHeight(null)*3, Image.SCALE_AREA_AVERAGING); // Tip: you should cache the scaled image and not scale it in the paint() method! // To draw it at x=100, y=200 g2.drawImage(img2, 100, 200, null);
2. Graphics.drawImage()
You can use different overloads of Graphics.drawImage() , where you can specify the size of the scalable image. You can "control" image quality with the KEY_INTERPOLATION rendering KEY_INTERPOLATION . It has 3 possible meanings:
VALUE_INTERPOLATION_NEAREST_NEIGHBOR, VALUE_INTERPOLATION_BILINEAR, VALUE_INTERPOLATION_BICUBIC
VALUE_INTERPOLATION_BILINEAR uses a bilinear interpolation algorithm of 4 nearest pixels. VALUE_INTERPOLATION_BICUBIC uses cubic interpolation from 9 neighboring pixels.
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); // To draw image scaled 3 times, x=100, y=200: g2.drawImage(img, 100, 200, img.getWidth(null)*3, img.getHeight(null)*3, null);
Sharp ribs
If you want to avoid sharp edges around the image, you should write a loop to move along the pixels along the edge of the image and set some transparency, for example. alpha = 0.5 (or alpha = 128). You can also do this on multiple rows / columns, for example. 0.8 alpha for the edge, 0.5 alpha for the 2nd line and 0.3 alpha for the 3rd line.