Problem with graphics again

Forum for J2ME mobile games related topics including programming doubts, books and other resources for J2ME game development

Problem with graphics again

Postby koey » Wed Mar 21, 2007 4:23 pm

I have a graphics which is 150*100 in dimension and 32KB, which can display properly on simulator by not in the real mobile. I guessed that it is the problem of size before, therefore, i have tried the create another graph with the same dimension but larger in size, however, it works!

Then, I also tried to create another graph with different dimension(larger), and it works also!

Do anyone here faced this kind of problem before? And do you know the reason for this?

I have tried once and when I use another software for creating the graphics, it works! but now, it doesn't.

And I also think that it is strange that when I just save the same graphic file with the same name but using different software, it can work......
koey
 
Posts: 44
Joined: Fri Jan 19, 2007 5:07 pm

Postby DevelopmentTeam » Thu Mar 22, 2007 3:47 am

yes, This kind of problem is related to the PNG or the file format you use, there are a large number of formats in which only a few is supported on the device. When we consider the PNG format some devices donot accept PNG24 or so. So you must better use a png optimizer after saving it with any software. This will help you to bring the format to support on all devices.
User avatar
DevelopmentTeam
Site Admin
 
Posts: 661
Joined: Tue Aug 15, 2006 8:39 am
Location: India

Postby DevelopmentTeam » Thu Mar 22, 2007 3:48 am

You can use PNGOUT for optimizing the png files. You can download the software here http://advsys.net/ken/utils.htm
User avatar
DevelopmentTeam
Site Admin
 
Posts: 661
Joined: Tue Aug 15, 2006 8:39 am
Location: India

Postby koey » Thu Mar 22, 2007 2:43 pm

Actually my graph is png8 only. I have tried to download the software, but the result is the same.
koey
 
Posts: 44
Joined: Fri Jan 19, 2007 5:07 pm

Postby DevelopmentTeam » Fri Mar 23, 2007 3:44 am

Let us first confirm things, I have met with same problem when I create png files from paint or another similar software. Now we use Photoshop and save is in PNG8 with 64 colors in the "save for web" option. You can also remove some unwanted colors. This is how we create pngs for our games. Always try to follow the same procedure for all images in your game. And can you send me the image file through email. enquiry@smackall.com.
User avatar
DevelopmentTeam
Site Admin
 
Posts: 661
Joined: Tue Aug 15, 2006 8:39 am
Location: India

Postby koey » Fri Mar 23, 2007 2:04 pm

I have sent an email to you already, thx a lot!!
koey
 
Posts: 44
Joined: Fri Jan 19, 2007 5:07 pm

Postby DevelopmentTeam » Fri Mar 23, 2007 2:46 pm

hey, sorry I think I missed your email, can you please sent me the picture again...
User avatar
DevelopmentTeam
Site Admin
 
Posts: 661
Joined: Tue Aug 15, 2006 8:39 am
Location: India

Postby koey » Fri Mar 23, 2007 2:59 pm

Doesn't matter, I sent again already
koey
 
Posts: 44
Joined: Fri Jan 19, 2007 5:07 pm

Postby DevelopmentTeam » Fri Mar 23, 2007 3:20 pm

Koey, I test the image you gave me, and it worked fine on my device. I tested it on N70, 6630 and SE K790i. there was no problem.
User avatar
DevelopmentTeam
Site Admin
 
Posts: 661
Joined: Tue Aug 15, 2006 8:39 am
Location: India

Postby DevelopmentTeam » Fri Mar 23, 2007 3:22 pm

The bug might be in your implementation, can you put the piece of code here which us use to load and show the image.
User avatar
DevelopmentTeam
Site Admin
 
Posts: 661
Joined: Tue Aug 15, 2006 8:39 am
Location: India

Postby koey » Fri Mar 23, 2007 3:42 pm

Code: Select all
   protected void paint(Graphics g) {
       
        g.setColor(0x00BC00);
        g.fillRect(0, 0, getWidth(), getHeight());
       

        if (MAX_ELE==0)
        try {
                   image = Image.createImage("/notable.png");
                   g.drawImage(image, 0, 0, 0);
          } catch (java.io.IOException e) { }
                
        for (int i=0; i<MAX_ELE; ++i){

           if (marker==i){
              try {
                   image = Image.createImage("/s_table.PNG");
                } catch (java.io.IOException e) { }
             }
             else{
                try {
                   image = Image.createImage("/table.PNG");
                } catch (java.io.IOException e) { }   
             }   
           g.drawImage(image, 0, 0+i*100, 0);
           
           g.setColor(0x000000);
           
           g.drawString(m_table, 50, 50+i*100, Graphics.BOTTOM | Graphics.LEFT);
           g.drawString(m_game, 40, 70+i*100, Graphics.BOTTOM | Graphics.LEFT);
       
           g.drawString(m_player[i][0], 55, 18+i*100, Graphics.BOTTOM | Graphics.LEFT);
           g.drawString(m_player[i][1], 5, 60+i*100, Graphics.BOTTOM | Graphics.LEFT);
           g.drawString(m_player[i][2], 110, 60+i*100, Graphics.BOTTOM | Graphics.LEFT);
           g.drawString(m_player[i][3], 55, 100+i*100, Graphics.BOTTOM | Graphics.LEFT);
           
         }
         
  }
koey
 
Posts: 44
Joined: Fri Jan 19, 2007 5:07 pm

Postby DevelopmentTeam » Fri Mar 23, 2007 3:58 pm

Code: Select all
    protected void paint(Graphics g) {
        try {
            g.setColor(0x00BC00);
            g.fillRect(0, 0, getWidth(), getHeight());
           
            if (MAX_ELE==0) {
                image = Image.createImage("/notable.png");
                g.drawImage(image, 0, 0, 0);
            } else {
                for (int i = 0; i < MAX_ELE; ++i){
                    if (marker == i)
                        image = Image.createImage("/s_table.PNG");
                    else
                        image = Image.createImage("/table.PNG");
                   
                    g.drawImage(image, 0, 0+i*100, 0);
                    g.setColor(0x000000);
                    g.drawString(m_table, 50, 50+i*100, Graphics.BOTTOM | Graphics.LEFT);
                    g.drawString(m_game, 40, 70+i*100, Graphics.BOTTOM | Graphics.LEFT);
                   
                    g.drawString(m_player[i][0], 55, 18+i*100, Graphics.BOTTOM | Graphics.LEFT);
                    g.drawString(m_player[i][1], 5, 60+i*100, Graphics.BOTTOM | Graphics.LEFT);
                    g.drawString(m_player[i][2], 110, 60+i*100, Graphics.BOTTOM | Graphics.LEFT);
                    g.drawString(m_player[i][3], 55, 100+i*100, Graphics.BOTTOM | Graphics.LEFT);
                }
            }
        } catch (java.io.IOException e) {
            e.printStackTrace();
        }
    }



I am not sure if the code will work now, coz I didnt understand the ultimate use of the code. But some tips are here for you,
1) Never load any resource (sound, image, text file) in paint method to just display an image construct all the images int he constructos and use it to display in the paint function.

Code: Select all
public class game extends Canvas {
       private Image img1= null;
       public game() {
             try {
                  img1 = Image.createImage("/hello.png");
             } catch (Exception ex) {
                  ex.printstacktrace();
             }
       }

       public void paint(Graphics g) {
             g.drawImage(img1, 0, 0, 0);
       }
}


Thanks
User avatar
DevelopmentTeam
Site Admin
 
Posts: 661
Joined: Tue Aug 15, 2006 8:39 am
Location: India

Postby koey » Fri Mar 23, 2007 4:28 pm

thx a lot, it works now!!!But actually why it is not good to doing so?
koey
 
Posts: 44
Joined: Fri Jan 19, 2007 5:07 pm

Postby DevelopmentTeam » Sat Mar 24, 2007 3:52 am

The Paint function is directly called by the main thread that JVM runs for this application, and if there is some 'time consuming' task it gets struck on refreshing the screen. And as you have loaded the image every time it refreshes the screen, it get struck and shows nothing. :) Always do 'Load once and use many times' idea.
User avatar
DevelopmentTeam
Site Admin
 
Posts: 661
Joined: Tue Aug 15, 2006 8:39 am
Location: India


Return to J2ME Games

Who is online

Users browsing this forum: Google [Bot] and 2 guests

cron