i want to strech image by using Graphics but unable here is my code it shows image in size that i want but not strach the image
void imageload () {
FileDialog fd = new FileDialog(MainFram.this,"Open", FileDialog.LOAD);
fd.show();
if(fd.getFile() == null){
//Label1.setText("You have not chosen any image files yet");
}else{
String d = (fd.getDirectory() + fd.getFile());
Toolkit toolkit = Toolkit.getDefaultToolkit();
Image1 = toolkit.getImage(d);
saveImage = d;//if user want to save Image
ImageIcon icon=new ImageIcon(Image1);
lblImage.setIcon(icon);
lblImage.setMinimumSize(new Dimension(50, 70));
lblImage.repaint();
}
}
解决方案
Call getScaledInstance() to scale the image to the size you want before you create the ImageIcon. You don't need to call setMinimumSize on the label.
Image image = toolkit.getImage("pic.jpg");
Image scaledImage = image.getScaledInstance(50, 70, Image.SCALE_DEFAULT);
ImageIcon icon=new ImageIcon(scaledImage);