You Are Here:

Community: Developer Discussion Boards

#1 Old Question Creating an object Image to handle... - 2009-03-12, 03:09

Join Date: Jan 2008
Posts: 18
Location: Brazil
Maxtremus
Offline
Registered User
I'm developing an aplication that uses only one Image object to handle images and show it in the screen, my problem is that it loads the same image file every loop, how do I fix it? Here's a short example of the code:

Code:
int x = 0;
Image img;
while(end == false){
    if(key == LEFT_PRESSED){
        x--;
    }
    if(key == RIGHT_PRESSED){
        x++;
    }

    switch(x){
        case 1:
            img = Image.createImage("/img01.png");
            break;
        case 2:
            img = Image.createImage("/img02.png");
            break;
        case 3:
            img = Image.createImage("/img03.png");
            break;
        case 4:
            img = Image.createImage("/img04.png");
            break;
        //case 5 ...
        //case 6 ...
        //case 7 ...
    }
    graphic.drawImage(img, 0, 0, Graphics.LEFT | Graphics.TOP);

}
Reply With Quote

#2 Old Re: Creating an object Image to handle... - 2009-03-12, 10:13

Join Date: Jun 2008
Posts: 96
Send a message via AIM to sharvan1981
sharvan1981's Avatar
sharvan1981
Offline
Regular Contributor
Hi,

You should do null of the image object on every event like that

int x = 0;
Image img;
while(end == false){
if(key == LEFT_PRESSED){
x--;
}
if(key == RIGHT_PRESSED){
x++;
}

switch(x){
case 1:
img=null;
img = Image.createImage("/img01.png");
break;
case 2:
img=null;
img = Image.createImage("/img02.png");
break;
case 3:
img=null;
img = Image.createImage("/img03.png");
break;
case 4:
img=null;
img = Image.createImage("/img04.png");
break;
//case 5 ...
//case 6 ...
//case 7 ...
}
graphic.drawImage(img, 0, 0, Graphics.LEFT | Graphics.TOP);

}
Reply With Quote

#3 Old Re: Creating an object Image to handle... - 2009-03-12, 12:45

Join Date: Jun 2003
Posts: 4,325
Location: Cheshire, UK
grahamhughes's Avatar
grahamhughes
Offline
Forum Nokia Champion
Quote:
Originally Posted by Maxtremus View Post
I'm developing an aplication that uses only one Image object to handle images and show it in the screen, my problem is that it loads the same image file every loop, how do I fix it?
There's nothing obviously wrong with the code you posted... but your problem may lie elsewhere.

Where is this code? It looks like it's from the run() method of a class than extends GameCanvas and implements Runnable, yes? In that case, you need to call flushGraphics().

No, you don't need to set the variable to null.

Loading images can be time consuming on some devices... unless the images are very large, you might consider loading them (for example, into an Image[]) ahead of time.

Cheers,
Graham.
Reply With Quote

#4 Old Re: Creating an object Image to handle... - 2009-03-12, 14:57

Join Date: Jan 2008
Posts: 18
Location: Brazil
Maxtremus
Offline
Registered User
Quote:
Originally Posted by grahamhughes View Post
There's nothing obviously wrong with the code you posted... but your problem may lie elsewhere.

Where is this code? It looks like it's from the run() method of a class than extends GameCanvas and implements Runnable, yes? In that case, you need to call flushGraphics().

No, you don't need to set the variable to null.

Loading images can be time consuming on some devices... unless the images are very large, you might consider loading them (for example, into an Image[]) ahead of time.

Cheers,
Graham.
Yes, it is in the run() method, I'm also using low level graphics programming (GameCanvas) because I want to make some effects after.

Using the Image[] does not fit here, because I'll have so many images, and loading them all before may take a long time to load and cause an Out of Memory exception, thats because I want a "real time" loading.
Reply With Quote

#5 Old Post Re: Creating an object Image to handle... - 2009-03-12, 15:09

Join Date: Feb 2009
Posts: 7
fletcher.jonnes
Offline
Registered User
Once I have a problem with the method run and a parameter. A function call with a parameter inside a run method, every time the call was with the first value of the parameter, to get it "working" I've changed the parameter for a class atributte. Maybe this help you.
Reply With Quote

#6 Old Re: Creating an object Image to handle... - 2009-03-12, 15:55

Join Date: Jun 2003
Posts: 4,325
Location: Cheshire, UK
grahamhughes's Avatar
grahamhughes
Offline
Forum Nokia Champion
Possible problems:

1. You aren't calling flushGraphics()... until you do this, nothing you draw will appear.

2. An exception is being thrown, and you're ignoring it.

3. "x" doesn't have the value you think it has.

4. You have two variables called "img", and one is hiding the other.

When you do this:

Code:
img = Image.createImage("/img02.png");
there are only two possible outcomes. Either:

1. img will refer to a new Image object, representing the data in /img02.png; or

2. An exception is thrown, and img is unchanged.

Nothing else can happen.

Cheers,
Graham.
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules

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

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
--- ???save image problem??? --- ferenn Mobile Java Media (Graphics & Sounds) 6 2007-10-01 15:33
Problem when creating Image !!! cvraiden Mobile Java Media (Graphics & Sounds) 3 2007-07-10 17:33
KERN-EXEC 0 when trying to access kernel object handle i.e. driver channel handle jayanjohn General Symbian C++ 0 2006-12-26 13:35
intercept/catch the image object Rx- Bluetooth Technology 0 2004-02-18 07:25
Get pixel data from an image object on Nokia phones? inopia Mobile Java General 1 2002-05-15 10:27

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomE2fforumE2fshowthreadE2ephpE3ftE3d18645X qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE44iscussionQ qdcZtypeQUqfntypeZE44iscussionContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZentertainmentQ qfnZtopicQUqfnTopicZj2meQ qfnZtopicQUqfnTopicZjavaQ qfnZtopicQUqfnTopicZmediaQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE44iscussionQ qfnZtypeQUqfntypeZE44iscussionContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE44iscussionQ qrdfZtypeQUqfntypeZE44iscussionContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ