Results 1 to 8 of 8

Thread: Images

  1. #1
    Witik is offline Member
    Join Date
    Sep 2010
    Posts
    5
    Rep Power
    0

    Default Images

    Hello, I'm having some trouble with the images.

    How to load the images in one class and use them in the other one?

    I have:
    Java Code:
        //maptile grass
        private Image Grass;
        //maptile rock
        private Image Rock;
    Java Code:
                Grass = ImageIO.read(new URL("file:///F:/Netbean/RPG_poging1/res/Grass.gif"));
                Rock = ImageIO.read(new URL("file:///F:/Netbean/RPG_poging1/res/Rock.gif"));
    in one class, and I need to use them in another as follows:
    Java Code:
                                    g.drawImage(Grass, 0, 0, null);
    				g.drawImage(Rock, 0, 0, null);
    Please Help :)

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,449
    Rep Power
    25

    Default

    Use the same technique as you would use to pass references to any object in one class to another to make references to the images available to the class/method with the drawImage() calls.
    For example, have a getRockImage method. Or have the class with the image call a method in the class that needs it and pass the reference.

    The fact that the objects are image makes no difference in how you code it.

  3. #3
    Witik is offline Member
    Join Date
    Sep 2010
    Posts
    5
    Rep Power
    0

    Default

    Thanks for you reply :)

    could you add an example, to elaborate it a bit more?

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,449
    Rep Power
    25

    Default

    Are you saying you don't know how to pass a reference from one class to another?
    Java Code:
    class AClass {
      Object obj;  // the object to be passed to the other class
    
       ...
      public Object getObject() {return obj;}  // Return ref to the object
    } 
    
    // The other class
    class BClass {
      AClass refA = ...;  // get a ref to AClass somehow
         ....
       Object = refA.getObject(); // get reference to the object in ClassA
        ...
    }

  5. #5
    Witik is offline Member
    Join Date
    Sep 2010
    Posts
    5
    Rep Power
    0

    Default

    Tnx :D got it working

  6. #6
    Join Date
    Sep 2010
    Posts
    1
    Rep Power
    0

    Default

    when i am reading an image in java through image.RGB i am getting the intensity value matrix in negative. plz suggest why i am getting such result rather.

  7. #7
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,449
    Rep Power
    25

    Default

    Please start a new thread for a new topic.

    Do you know the format for RGB values. There are 4 bytes in the int value. If the top bit is on, the int will be negative.

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

    Default

    Quote Originally Posted by gauravsanthalia View Post
    when i am reading an image in java through image.RGB i am getting the intensity value matrix in negative. plz suggest why i am getting such result rather.
    As Norm stated, please start your own thread rather than hijack an old one. I'm locking this thread.

Similar Threads

  1. XML Images
    By JavaWizz in forum XML
    Replies: 1
    Last Post: 10-17-2008, 10:19 AM
  2. images
    By amith in forum AWT / Swing
    Replies: 3
    Last Post: 06-27-2008, 08:38 PM
  3. images
    By amith in forum AWT / Swing
    Replies: 1
    Last Post: 05-20-2008, 10:54 AM
  4. Help with images...
    By toby in forum Java Applets
    Replies: 1
    Last Post: 08-04-2007, 05:25 AM
  5. Images in JSP
    By Daniel in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 06-05-2007, 06:01 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
  •