How can you get a buffered image to resize to fill a panel?
So for example you have a picture that is 20x20 pixels in its natural size. Your panel is 100x100 pixels. Resizing the panel is not an option because there is no guarantee the picture will always be 20x20.
Currently the way I am drawing the picture is:
Code:
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.ImageIO;
import javax.swing.JPanel;
//@SuppressWarnings("serial")
public class DisplayImage extends JPanel
{
BufferedImage image;
public DisplayImage(String picPath)
{
File input = new File(picPath);
image = ImageIO.read(input);
}
public DisplayImage(LayoutManager layout, String picPath)
{
this(picPath);
setLayout(layout);
setDoubleBuffered(true);
setOpaque(true);
updateUI();
}
public void setImage(String picPath)
{
File input = new File(picPath);
image = ImageIO.read(input);
}
public void paint(Graphics g)
{
g.drawImage(image, 0, 0, null);
}
}
Re: How can you get a buffered image to resize to fill a panel?
Isn't there a drawImage() that lets you specify the target size?
Re: How can you get a buffered image to resize to fill a panel?
Yeah there is, thanks that did the trick
Re: How can you get a buffered image to resize to fill a panel?
Moved from New to Java
db