Results 1 to 2 of 2
  1. #1
    swimmy101 is offline Member
    Join Date
    Feb 2009
    Posts
    1
    Rep Power
    0

    Default Importing Picture into Java Code

    Hi I am taking a Computer Science Class in which I learn about Java code. I am fairly new so I don't understand a lot of it.

    My teacher gave me an assignment in which I had to create multiple scenes. I am wanting to import a picture of someone's face and I don't know how to do it. We are using drawString, and drawRect, etc.... so if the code you suggest could be fairly simple that would be great. I would be plugging it into coordinates (ie drawString("1",240,560);

    Thank you!!!

  2. #2
    kzvi.kzvi.1 is offline Member
    Join Date
    Oct 2008
    Location
    US
    Posts
    58
    Rep Power
    0

    Thumbs up

    I would suggest something like this...

    Image image = null;
    try {
    // Read from a file
    File sourceimage = new File("source.gif");
    image = ImageIO.read(sourceimage);

    // Read from an input stream
    InputStream is = new BufferedInputStream(
    new FileInputStream("source.gif"));
    image = ImageIO.read(is);

    // Read from a URL
    URL url = new URL("http://java-tips.org/source.gif");
    image = ImageIO.read(url);
    } catch (IOException e) {
    }

    // Use a label to display the image
    JFrame frame = new JFrame();
    JLabel label = new JLabel(new ImageIcon(image));
    frame.getContentPane().add(label, BorderLayout.CENTER);
    frame.pack();
    frame.setVisible(true);

    Keep this in your main method and look at the javax.image api docs for making changes to image object.


    )=====================================>>
    Njoy,
    Software Wiki | Java | Searching | Database | Hibernate | J2EE Frameworks| Job Tips | I Luv Linux
    Have fun....
    JAVA FAQs

Similar Threads

  1. importing .java files into eclipse
    By nickl2002 in forum Eclipse
    Replies: 1
    Last Post: 01-19-2009, 12:06 AM
  2. Replies: 10
    Last Post: 10-30-2008, 05:57 PM
  3. picture backround
    By safiya in forum NetBeans
    Replies: 1
    Last Post: 10-18-2008, 08:13 AM
  4. Picture help
    By deathnote11 in forum AWT / Swing
    Replies: 13
    Last Post: 06-03-2008, 06:46 PM
  5. Print a picture file
    By oli001 in forum New To Java
    Replies: 0
    Last Post: 11-26-2007, 02:40 PM

Posting Permissions

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