Results 1 to 4 of 4
  1. #1
    wokena is offline Member
    Join Date
    Dec 2008
    Posts
    2
    Rep Power
    0

    Unhappy ImageIcon and size

    Hi guys,
    I have problem,I´want change size at ImageIcon,but I can´t it.This is my code:

    Java Code:
    package dalsik;
    import java.awt.*;
    import javax.swing.*;
    import java.net.*;
     
     
    public class Main extends JFrame{
     
     
        public Main() throws Exception{
       super("None");
        setSize(400,400);
     
        Container c=getContentPane();
        FlowLayout layout=new FlowLayout();
        c.setLayout(layout);        
     
        ImageIcon vv=new ImageIcon("C:\\image.jpg");  //  I want resize this picture (image.jpg)
        JLabel jl=new JLabel("",vv,JLabel.LEFT);
        c.add(jl);
     
     
     
     
        setDefaultCloseOperation(EXIT_ON_CLOSE);
    setVisible(true);
    }
     
     
        public static void main(String[] args) throws Exception{
           Main m=new Main();m.setVisible(true);
        }
     
    }
    Can you help me??
    Thanks for your answers.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    So, rather than reply to morgalr's reply to your original post in the Sun Java forums here: Java 2D - ImageIcon and size

    You have decided to waste someone else's time by cross-posting this same question here. That's not very considerate of you.

  3. #3
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Java Code:
    import java.awt.*;
    import java.awt.image.BufferedImage;
    import java.net.URL;
    import javax.swing.*;
    
    public class MainResize extends JFrame {
        public MainResize() {
            super("None");
    //        setSize(400,400);
            Container c=getContentPane();
            c.setLayout(new GridLayout(1,0));        
            //  I want resize this picture (image.jpg)
            String path = //"images/bison.jpg";
                          "C:/image.jpg";
            URL url = getClass().getResource(path);
            System.out.println("url = " + url);
            ImageIcon vv=new ImageIcon(url);
            JLabel jl=new JLabel("",vv,JLabel.LEFT);
            c.add(jl);
            c.add(new JLabel(scale(vv.getImage(), 0.75)));
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            pack();
            setVisible(true);
        }
    
        private ImageIcon scale(Image src, double scale) {
            int w = (int)(scale*src.getWidth(this));
            int h = (int)(scale*src.getHeight(this));
            int type = BufferedImage.TYPE_INT_RGB;
            BufferedImage dst = new BufferedImage(w, h, type);
            Graphics2D g2 = dst.createGraphics();
            g2.drawImage(src, 0, 0, w, h, this);
            g2.dispose();
            return new ImageIcon(dst);
        }
    
        public static void main(String[] args) {
            new MainResize();
        }
    }

  4. #4
    wokena is offline Member
    Join Date
    Dec 2008
    Posts
    2
    Rep Power
    0

    Default

    to hardwired:Thank you verry much!
    Last edited by wokena; 12-21-2008 at 08:49 AM.

Similar Threads

  1. String max size
    By eva in forum New To Java
    Replies: 0
    Last Post: 01-31-2008, 02:29 PM
  2. Detect loading of ImageIcon from URL?
    By barkster in forum Java Applets
    Replies: 1
    Last Post: 01-29-2008, 07:04 PM
  3. File size
    By eva in forum New To Java
    Replies: 2
    Last Post: 12-19-2007, 09:27 AM
  4. Object size
    By kavithas in forum New To Java
    Replies: 0
    Last Post: 11-30-2007, 12:00 PM
  5. copy image/imageicon into a file on disk
    By archanajathan in forum Advanced Java
    Replies: 2
    Last Post: 11-22-2007, 06:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •