Results 1 to 8 of 8
Like Tree1Likes
  • 1 Post By JosAH

Thread: Help me!

  1. #1
    aelynne is offline Member
    Join Date
    Oct 2011
    Posts
    15
    Rep Power
    0

    Default Help me!

    Hello, i want to know how to open an image in java? For example, I already have an image .jpg, and i need to open it in java so that i can do the image processing. Anybody can help me?

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,001
    Blog Entries
    7
    Rep Power
    20

    Default Re: Help me!

    Have a look at the ImageIO class; it has methods that can read image files and create a BufferedImage out of them. You can also try to use the ImageIcon class ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    aelynne is offline Member
    Join Date
    Oct 2011
    Posts
    15
    Rep Power
    0

    Default Re: Help me!

    I have try this coding, but i can't open the image. I don't know why.

    import java.awt.image.BufferedImage;
    import java.io.File;
    import javax.imageio.ImageIO;

    File file = new File("sign.jpg");
    BufferedImage img;
    img = ImageIO.read(file);

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,001
    Blog Entries
    7
    Rep Power
    20

    Default Re: Help me!

    Maybe your program runs in a directory different from where your sign.jpg file is stored; try to use an absolute path name, e.g. "c:/usr/foo/sign.jpg". If you want to see where your program is running, add the following line:

    Java Code:
    System.out.println(System.getProperty("user.dir"));
    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    aelynne is offline Member
    Join Date
    Oct 2011
    Posts
    15
    Rep Power
    0

    Default Re: Help me!

    It still have error. Is it have different kind of coding if I use drjava software? Here i attach a picture shown the error when I compile it Help me!-untitled.jpgHelp me!-untitled2.jpg

  6. #6
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default Re: Help me!

    Where is your class?
    Where is your methods?

  7. #7
    aelynne is offline Member
    Join Date
    Oct 2011
    Posts
    15
    Rep Power
    0

    Default Re: Help me!

    class? method? I'm sorry but I have zero knowledge about java.

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,001
    Blog Entries
    7
    Rep Power
    20

    Default Re: Help me!

    Quote Originally Posted by aelynne View Post
    class? method? I'm sorry but I have zero knowledge about java.
    Java is not Basic; in Java all you can do is define classes and/or interfaces; inside those classes you can define methods and inside those methods you can have statements; better read a textbook first before you try to code anything.

    kind regards,

    Jos
    Fubarable likes this.
    cenosillicaphobia: the fear for an empty beer glass

Posting Permissions

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