I'm trying to scale an image (my last goal is to perform anti-aliasing on an image) but I see a white screen after scaling. how am I supposed to use the getScaledInstance() method to scale an image? I'm learning java and I never used this before. I checked out two similar questions in here(this and this one and also this one) but I didn't understand. I think I need a completer explanation.
this is how I'm doing this:
private void imageScanner(String C_imagePath, String N_imagePath, int N_WIDTH, int N_HEIGHT) throws IOException {
System.out.println("imageScanner started.");
Image image = new ImageIcon(C_imagePath).getImage();
image = image.getScaledInstance(N_WIDTH * 20, N_HEIGHT * 20, Image.SCALE_SMOOTH);
BufferedImage bi = new BufferedImage(N_WIDTH * 20, N_HEIGHT * 20, BufferedImage.TYPE_INT_ARGB);
bi.getGraphics().drawImage(image, 0, 0, N_WIDTH * 20, N_HEIGHT * 20, null);
try {
ImageIO.write(bi, "png", new File(N_imagePath));
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("imageScanner is done.");
}
I also tried to wrap it with imageIcon (like this: image = new ImageIcon(image.getScaledInstance(N_WIDTH * 20, N_HEIGHT * 20, Image.SCALE_SMOOTH)).getImage();) to sovle this problem and acually the white screen problem solved but I don't see any differece. I'm trying not to do anti-aliasing using Graphics2D but if it is not the only way of performing anti-aliasing.
EDIT: actually, the white screen problem solved and now the main problem is I don't see any difference.
without using image = new ImageIcon(image.getScaledInstance(N_WIDTH * 20, N_HEIGHT * 20, Image.SCALE_SMOOTH)).getImage();
with using image = new ImageIcon(image.getScaledInstance(N_WIDTH * 20, N_HEIGHT * 20, Image.SCALE_SMOOTH)).getImage();