Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to stretch image

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();
    }
}
like image 348
user542719 Avatar asked Jan 19 '11 08:01

user542719


People also ask

How do I stretch a picture without distorting it?

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.

How do I stretch a picture on my phone?

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.


1 Answers

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);
like image 181
dogbane Avatar answered Sep 19 '22 00:09

dogbane