The task: I have some images, I scale them down, and join them to one image. But I have a little problem with the implementation:
The concr
Maybe this method will help:
public BufferedImage resizeImage(BufferedImage image, int width, int height) {
int type=0;
type = image.getType() == 0? BufferedImage.TYPE_INT_ARGB : image.getType();
BufferedImage resizedImage = new BufferedImage(width, height,type);
Graphics2D g = resizedImage.createGraphics();
g.drawImage(image, 0, 0, width, height, null);
g.dispose();
return resizedImage;
}
Don't forget those "import" lines:
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
And about casting:
The abstract class Image
is the superclass of all classes that represent graphical images.
We can't cast Image
to BufferedImage
because every BufferedImage
is Image
but vice versa is not true.
Image im = new BufferedImage(width, height, imageType);//this is true
BufferedImage img = new Image(){//.....}; //this is wrong