|
| displaying counter works so slowly |
 |
Thu, 08 Dec 2005 13:32:39 +010 |
Hello,
I wrote the application with seconds counter. The application with
counter works fine on emulator and phone, when paint method has only
drawString function. The problem appears when I add to paint method a
few images to display. The counter starts working slowly on the phone.
I see displaying seconds after 3 seconds of realtime.
I cannot figure out the problem. I tested it on nokia 6600.
Thanks,
David
public class CCanvas extends FullCanvas
implements Runnable
{
Thread thread;
int counter;
Image imageOffscreen;
public CCanvas()
{
thread = new Thread(this);
thread.start();
counter = 0;
try
{
imageOffscreen =
Image.createImage(getWidth(),getHeight());
}
catch(Exception ex) {}
}
public void paint(Graphics g)
{
Graphics gfx = imageOffscreen.getGraphics();
gfx.setColor(0);
gfx.drawString(""+counter/10,50,50);
//
// Add more graphics and images to display here
//
g.drawImage(imageOffscreen,0,0,20);
}
public void run()
{
while(1)
{
if(counter++ % 10 == 0)
repaint();
try
{
Thread.sleep(100L);
}
catch(Exception ex) {}
}
}
|
| Post Reply
|
| Re: displaying counter works so slowly |
 |
Thu, 8 Dec 2005 19:01:38 -0000 |
Hi David
I can't actually reproduce this on a Nokia 6600, although I was using Canvas
and setFullScreenMode, rather than FullCanvas which is a Nokia specific
extension (and I think deprecated). On my phone it increments the count
approximately every second.
Also note that on Symbian's MIDP I believe the underlying native
implementation of Canvas is double buffered anyway (you can check this by
calling isDoubleBuffered() ) so coding your own off screen buffer to achieve
double buffering is a waste. I suggest you take all that getGraphics()
nastiness out of your paint loop.
public void paint(Graphics g) {
g.drawImage(image, 0, 0, Graphics.TOP|Graphics.LEFT);
g.setColor(0);
g.drawString(""+ counter/10, 50, 50,
Graphics.BASELINE|Graphics.LEFT);
}
Create you images before hand and just draw them in the paint method. Set
clipping regions if necessary.
Regards
Martin
"David Lovecraft" <DiL@nospam.com> wrote in message
news:x82lYM$%23FHA.2948@extapps30...
>
> Hello,
>
>
> I wrote the application with seconds counter. The application with
> counter works fine on emulator and phone, when paint method has only
> drawString function. The problem appears when I add to paint method a
> few images to display. The counter starts working slowly on the phone.
> I see displaying seconds after 3 seconds of realtime.
> I cannot figure out the problem. I tested it on nokia 6600.
>
> Thanks,
>
> David
>
>
>
> public class CCanvas extends FullCanvas
> implements Runnable
> {
> Thread thread;
> int counter;
> Image imageOffscreen;
>
> public CCanvas()
> {
> thread = new Thread(this);
> thread.start();
> counter = 0;
> try
> {
> imageOffscreen =
> Image.createImage(getWidth(),getHeight());
> }
> catch(Exception ex) {}
> }
>
> public void paint(Graphics g)
> {
> Graphics gfx = imageOffscreen.getGraphics();
> gfx.setColor(0);
>
> gfx.drawString(""+counter/10,50,50);
> //
> // Add more graphics and images to display here
> //
> g.drawImage(imageOffscreen,0,0,20);
> }
>
> public void run()
> {
> while(1)
> {
> if(counter++ % 10 == 0)
> repaint();
> try
> {
> Thread.sleep(100L);
> }
> catch(Exception ex) {}
> }
> }
> }
|
| Post Reply
|
| Re: displaying counter works so slowly |
 |
Fri, 09 Dec 2005 10:53:50 +010 |
Hi Martin,
I have already solved my problem. I create new TimerTask in singleton
class to count down my seconds. Everything works like a charm!
Thanks Martin for help anyway,
David
Martin wrote:
> Hi David
>
> I can't actually reproduce this on a Nokia 6600, although I was using
Canvas
> and setFullScreenMode, rather than FullCanvas which is a Nokia specific
> extension (and I think deprecated). On my phone it increments the count
> approximately every second.
>
> Also note that on Symbian's MIDP I believe the underlying native
> implementation of Canvas is double buffered anyway (you can check this by
> calling isDoubleBuffered() ) so coding your own off screen buffer to
achieve
> double buffering is a waste. I suggest you take all that getGraphics()
> nastiness out of your paint loop.
>
> public void paint(Graphics g) {
> g.drawImage(image, 0, 0, Graphics.TOP|Graphics.LEFT);
> g.setColor(0);
> g.drawString(""+ counter/10, 50, 50,
> Graphics.BASELINE|Graphics.LEFT);
> }
>
> Create you images before hand and just draw them in the paint method. Set
> clipping regions if necessary.
>
> Regards
> Martin
>
>
> "David Lovecraft" <DiL@nospam.com> wrote in message
> news:x82lYM$%23FHA.2948@extapps30...
>
>>Hello,
>>
>>
>>I wrote the application with seconds counter. The application with
>>counter works fine on emulator and phone, when paint method has only
>>drawString function. The problem appears when I add to paint method a
>>few images to display. The counter starts working slowly on the phone.
>>I see displaying seconds after 3 seconds of realtime.
>>I cannot figure out the problem. I tested it on nokia 6600.
>>
>>Thanks,
>>
>>David
>>
>>
>>
>>public class CCanvas extends FullCanvas
>>implements Runnable
>>{
>> Thread thread;
>> int counter;
>> Image imageOffscreen;
>>
>> public CCanvas()
>> {
>> thread = new Thread(this);
>> thread.start();
>> counter = 0;
>> try
>> {
>> imageOffscreen =
>>Image.createImage(getWidth(),getHeight());
>> }
>> catch(Exception ex) {}
>> }
>>
>> public void paint(Graphics g)
>> {
>> Graphics gfx = imageOffscreen.getGraphics();
>> gfx.setColor(0);
>>
>> gfx.drawString(""+counter/10,50,50);
>>//
>>// Add more graphics and images to display here
>>//
>>g.drawImage(imageOffscreen,0,0,20);
>> }
>>
>> public void run()
>> {
>> while(1)
>> {
>> if(counter++ % 10 == 0)
>> repaint();
>> try
>> {
>> Thread.sleep(100L);
>> }
>> catch(Exception ex) {}
>> }
>> }
>>}
>
>
|
| Post Reply
|
|
|