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

    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
    Rep Power

    Thumbs up

    I would suggest something like this...

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

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

    // Read from a URL
    URL url = new URL("");
    image =;
    } 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);

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

    Software Wiki | Java | Searching | Database | Hibernate | J2EE Frameworks| Job Tips | I Luv Linux
    Have fun....

Similar Threads

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