×

Discussion Board

Results 1 to 14 of 14
  1. #1
    Regular Contributor
    Join Date
    Jul 2008
    Posts
    72

    Displaying one image on top of another image in J2ME

    Hello frens,

    I need some help how to display one image on the top of next image. Here i have to .PNG images and i need to draw one image on the top of another.

    can anyone tell how this can be achieved?

    Thanks

  2. #2
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,406

    Re: Displaying one image on top of another image in J2ME

    Hi amishra,

    if you're using Canvas, you can do it by simply using the drawImage() method, and using appropriate x and y coordinates.

    Pit

  3. #3
    Super Contributor
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: Displaying one image on top of another image in J2ME

    Hi,

    I'm not sure I understand your question. But here's how I think it can be done (if this is not what you meant please explain your request in detail):
    -create a Canvas
    -display the first image
    -display the second image on top of it
    Here is the canvas code I tested:
    Code:
    import javax.microedition.lcdui.*;
    
    public class MyCanvas extends Canvas {
        
        public void paint(Graphics g) {
            try {
                Image img1=Image.createImage("/src/a.PNG");
                Image img2=Image.createImage("/src/b.PNG");
                //Display the first image
                g.drawImage(img1, 0, 0, Graphics.TOP|Graphics.LEFT);
                //Display the second one
                g.drawImage(img2, 0, 0, Graphics.TOP|Graphics.LEFT);
            }
            catch(Exception e) {
                
            }
        }
        
    }

  4. #4
    Regular Contributor
    Join Date
    Jul 2008
    Posts
    72

    Re: Displaying one image on top of another image in J2ME

    thanks

    Yes i am working in canvas. I will try the codes and let you know if anything goes wrong.

    Can we display more then 2 pictures also?

  5. #5
    Super Contributor
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: Displaying one image on top of another image in J2ME

    Basically you can display as many pictures as you want, though if they are many and large you might eventually have some problems with the phone running out of memory.

  6. #6
    Regular Contributor
    Join Date
    Jul 2008
    Posts
    72

    Re: Displaying one image on top of another image in J2ME

    thanks friends that worked well, now the next query is i have a image that is quit big ( 1024 * 860 ) and i can display 240 * 320 at a time on the screen.

    how can i move the image to show it? I mean using the key on mobile phones?


    Looking for reply friends

  7. #7
    Super Contributor
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: Displaying one image on top of another image in J2ME

    Well you could display a part of the image using the drawRegion(...) method and when the navigation keys are pressed display the next part accordingly. See the Graphics.drawRegion() method documentation and Alessandro's recent article, How to build a Canvas based list in Java ME.

  8. #8
    Super Contributor
    Join Date
    Apr 2007
    Posts
    2,708

    Re: Displaying one image on top of another image in J2ME

    u might also want to try with the LayerManager and make sprites out of those images...

  9. #9
    Regular Contributor
    Join Date
    Jul 2008
    Posts
    72

    Re: Displaying one image on top of another image in J2ME

    Hello,

    I looked at the examples, but i didn't find the solution that I needed. Can you explain in details a bit so that i can get idea how to use? Or if there are any other examples that could really help me.

    Looking for your reply.

    Thanks

  10. #10
    Regular Contributor
    Join Date
    Jul 2008
    Posts
    72

    Re: Displaying one image on top of another image in J2ME

    Hello,

    I am able to scroll the image, but the problem is it repeats again. I want to stop if the image is at the end on the screen. How can i do this?

    is there any way to handle this?

    thanks

  11. #11
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,406

    Re: Displaying one image on top of another image in J2ME

    Hi amishra,

    you should manually check it by comparing the y scroll coordinate and the Image height (using the getHeight() method). More detailed replies would highly depend on the scrolling logic you've implemented, but something like this should work:
    Code:
    if(yScrollCoordinate + screenHeight > yourImage.getHeight())
    {
    // DO NOT SCROLL
    }
    Pit

  12. #12
    Regular Contributor
    Join Date
    Jul 2008
    Posts
    72

    Re: Displaying one image on top of another image in J2ME

    Thanks for the reply.

    But i have implemented in different way and its working fine now.

    anyway thanks for the reply

  13. #13
    Registered User
    Join Date
    Nov 2008
    Posts
    1

    Re: Displaying one image on top of another image in J2ME

    hi guys ,
    I am trying to develop a map based location service software for mobile phones. I am facing a tedious problem of image. I have a bigger image ,i can reduce the size and then i can display it but i want to display the larger image.While i am trying to do so only the one part of image is being displayed the maximum which fits over screen at one time. I saw your discussion and i found that one of you have found the solution (amishra).So, if you can give me that code or can give any idea then that will really help me a lot. I will be really thankful to you.

    you can send your mail to me at my id
    sandeepdas.cse@gmai.com

  14. #14
    Super Contributor
    Join Date
    Apr 2007
    Posts
    2,708

    Re: Displaying one image on top of another image in J2ME

    I yhink u are talking about resizing the map...
    cause it will only show the one part of it and specifically a part that is as big as the screen itself (in pixels), you would like to see the whole map on the screen, which actually means resizing whilst amishra is using scrolling...
    so please first try to choose what u'd like : resizing (fitting image to screen) or scrolling ?
    cause the resizing part will munch up insane amounts of memory on ur mobile (especially if the image is bigger than ur screen), but u could leave the resizing part for ur map-provider...

Similar Threads

  1. Replies: 0
    Last Post: 2006-03-11, 11:22
  2. Displaying image
    By kapot in forum Mobile Java Media (Graphics & Sounds)
    Replies: 3
    Last Post: 2004-11-16, 10:10
  3. Image is not displaying
    By dotcdotc in forum Mobile Java General
    Replies: 2
    Last Post: 2004-04-13, 12:26
  4. Problem displaying background image
    By advocatee in forum Symbian User Interface
    Replies: 3
    Last Post: 2003-11-18, 13:30
  5. Replies: 1
    Last Post: 2003-04-22, 13:56

Posting Permissions

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