×

Discussion Board

Results 1 to 6 of 6

Thread: Png Loading

  1. #1
    Regular Contributor
    Join Date
    Mar 2003
    Posts
    82

    Png Loading

    Hi !
    Is it normal that it takes about 3 seconds to load a 176x208 png image on a 7650 (the real device).
    Don't you think it's a long long time... we have to wait 3 seconds in the menus for examples just to show a credits screen !!!

    All I do is a
    Image tmp = mage.createImage(fileName);

    Does someone has an idea or a comment ?

    Thanks

  2. #2
    Registered User
    Join Date
    May 2003
    Posts
    39
    you might want to show your full source code, coz i do load big images but it doesn't require 3 seconds. Did you try on the actual device?

  3. #3
    Regular Contributor
    Join Date
    Mar 2003
    Posts
    82
    Here's my code. Note that I tested on the real Nokia 7650 and it takes about 3 seconds to switch between images. The images are 176x208 png of about 20Ko.
    Thanks

    public class ScreenManager extends FullCanvas implements Runnable
    {
    protected Image background;
    protected Graphics backgroundGfx;
    protected Midlet parent = null;
    private static ScreenManager instance = null;
    private Thread t;
    private byte state; // state of the game

    private ScreenManager(Midlet parent)
    {
    this.parent = parent; // save the parent
    state = 0;
    t=new Thread(this);
    t.start();
    try
    {
    background = Image.createImage(GfxSystem.gfxDir+"title.png");
    backgroundGfx = background.getGraphics();
    }
    catch( Exception e )
    {
    System.out.println(e.getMessage());
    }
    } /* constructor Screen */

    public static void initInstance(Midlet parent)
    {
    if( instance == null )
    instance = new ScreenManager(parent);
    } /* initInstance */

    public static ScreenManager getInstance()
    {
    return instance;
    } /* getInstance */

    protected void paint( Graphics g )
    {
    g.drawImage( background,0,0,0 );
    } /* paint */

    /**
    * keyPressed
    *
    * called if a key has been hit
    */
    protected void keyPressed( int keyCode )
    {
    String backFile = null;
    if ( state == 0 )
    backFile = new String("credits.png");
    if ( state == 1 )
    backFile = new String("gamescreen.png");
    if ( state == 2 )
    backFile = new String("title.png");
    if( state == 3 )
    parent.notifyDestroyed();
    state++;
    try
    {
    background = Image.createImage(GfxSystem.gfxDir+backFile);
    backgroundGfx = background.getGraphics();
    }
    catch( Exception e )
    {
    System.out.println(e.getMessage());
    parent.notifyDestroyed();
    }

    } /* keyPressed */

    /**
    * run
    */
    public void run()
    {
    running = true;
    while( running )
    {
    repaint();
    } // end while running
    } /* run */

    } /* Screen class */

  4. #4
    Super Contributor
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    2,280
    Loading an Image should definitely take a lot less than a few seconds.
    public void run()
    {
    running = true;
    while( running )
    {
    repaint();
    } // end while running
    } /* run */
    I think this is your problem. You are queuing up a LOT of repaint()s without waiting for the previous ones to finish, so I think you app just spends a while catching up on old repaint()s after you have changed the picture. Try with a serviceRepaints() in there right after the repaint(). Or even better find a more appropiate way to animate the canvas...

    shmoove

  5. #5
    Regular Contributor
    Join Date
    Mar 2003
    Location
    Helsinki.FI
    Posts
    112
    Paint doesn't seem to do anything else but just put the image to the screen. Why bother doing that repeatedly if a simple repaint(); with serviceRepaints(); call in the key detection method will do the trick as well?

    Kind regards,
    Tinke / FN

  6. #6
    Regular Contributor
    Join Date
    Mar 2003
    Posts
    82
    you were right, it was this thread who ran again and again.
    The code is a very simplified version... I need to repaint continusly
    because they are a lot of things moving on the screen.
    But now it's ok, I stop the thread when I don't need to draw the screen
    Thanks

Posting Permissions

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