I want to re-size my ImageIcon to fit my jLabel. Using the answer from this post Scale the ImageIcon automatically to label size I am using
public jfrmHome() {
initComponents();
this.setLocationRelativeTo(null);
ImageIcon iconimage;
iconimage = new ImageIcon(getClass().getResource("/org/me/musiconweb/resources/Music-icon.png"));
BufferedImage bi = new BufferedImage(iconimage.getIconWidth(), iconimage.getIconHeight(), BufferedImage.TYPE_INT_RGB);
Graphics g = bi.createGraphics();
iconimage.paintIcon(null, g, 0,0);
g.dispose();
BufferedImage resizedimage=resize(bi,jlblPicture.getWidth(), jlblPicture.getHeight());
ImageIcon resizedicon=new ImageIcon(resizedimage);
jlblPicture.setIcon(resizedicon);
}
This re-sizes the Image but i have a little problem. The background of the image becomes black instead of white that it was
This
turns to
Please what am i doing wrong?