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();
}
}
Another way to stretch an image without distorting it is to use the “Content-Aware Scale” command. With the “Content-Aware Scale” command, you can simply click and drag on the part of the image that you want to stretch. Photoshop will automatically determine how to best stretch the image without distorting it.
Tap the image you want to adjust. You can adjust the size of an image or rotate it: Resize: Touch and drag the squares along the edges. Rotate: Touch and drag the circle attached to the image.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With