slow update of canvas - 30s wait
i developed an application that draw square on a canvas. after some algorithm, the location of the square is moved. i need to draw the new location of that square on the same canvas. however, when i use the repaint() command, i need to wait around 30s for the canvas to be updated. why is this? is this normal? if it isnt, why is it behaviour this way?
please help
Re: slow update of canvas - 30s wait
Hi this is not normal have u used sleep in your code also is it happening on device or simulator if device what device u r using
Also a snap of your code will be more helpful to solve out your problem
Re: slow update of canvas - 30s wait
also are you creating a multi-threaded application ?
Re: slow update of canvas - 30s wait
public class testFirstAppTwo extends MIDlet implements CommandListener{
private AppCanvas testAppCanvas;
private Display display;
private Command exit,start,stop;
private Player player;
private VideoControl control;
private byte[] raw = null;
private byte[] raw2 = null;
private Image image=null;
private Image image2=null;
public testFirstAppTwo(){
exit = new Command("Exit", Command.EXIT, 0);
start = new Command("Start", Command.SCREEN, 0);
stop = new Command("Stop", Command.SCREEN, 0);
}
public void startApp() {
testAppCanvas = new AppCanvas();
testAppCanvas.addCommand(exit);
testAppCanvas.addCommand(start);
testAppCanvas.setCommandListener(this);
display = Display.getDisplay(this);
display.setCurrent(testAppCanvas);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable arg1) {
if(c == start)
{
startVideoThread();
}
else if(c == exit)
{
destroyApp(true);
notifyDestroyed();
}
else if (c == stop)
{
}
}
public void startVideoThread(){
try
{
player = Manager.createPlayer("capture://video");
player.realize();
control = (VideoControl)player.getControl("VideoControl");
control.initDisplayMode(VideoControl.USE_DIRECT_VIDEO,Display.getDisplay(this).getCurrent());
control.setVisible(false);
player.start();
}
catch(Exception e)
{
}
try
{
raw = control.getSnapshot("encoding=bmp");
image = Image.createImage(raw, 0, raw.length);
raw2 = control.getSnapshot("encoding=bmp");
image2 = Image.createImage(raw2, 0, raw2.length);
// some processing is done here
cuMVx=(cuMVx+vH)/2;
cuMVy=(cuMVy+vV)/2;
int x = testAppCanvas.positionX; int newPosX = cuMVx+x;
int y = testAppCanvas.positionY; int newPosY = cuMVy+y;
testAppCanvas.change(newPosX,newPosY);
Display.getDisplay(this).setCurrent(testAppCanvas);
}
catch(Exception exc)
{
}
player.close();
player = null;
control = null;
}
}
public class AppCanvas extends Canvas{
public int randomW,randomV;
public int positionX, positionY;
private int canvasWidth,canvasHeight;
public AppCanvas(){
Initialize();
}
private void Initialize(){
positionX = 30; positionY = getHeight()/2;
randomW = 100; randomV = getHeight()/2;
}
protected void paint(Graphics g) {
g.setColor(0x000000);
g.fillRect(randomW,randomV,40,40);
g.setColor(0x0000ff);
g.fillRect(positionX,positionY,40,40);
}
public void change(int x, int y){
positionX = x;
positionY = y;
repaint();
}
}
The code is as above. Please advise. No, i dont run multi-threading.
Re: slow update of canvas - 30s wait
btw, i am using N96. from specification SDK for N96 is s60 feature pack 2. I couldnt find s60 feature pack 2 to download. I think nokia discontinue it. So for my development i use s60 feature pack 1. Does it affect the slowness, somehow?
Re: slow update of canvas - 30s wait
Till now every app that I made if uses canvas runs in thread for repaintaing the canvas again and again which is not in your case I suggest to use thread for your canvas class and repaint the canvas in that thread.
Re: slow update of canvas - 30s wait
Hello,
As you have mentioned that you have to just move the shapes that you are drawing like the rect or so,and you are drawing the same using the "start" command.
[B]is this true?[/B]
if yes then why are you doing all the videos operations, like creating player and all the related stuff?
and then why are you starting the player?
this will offcourse will take the enough time to do these many operation...
[QUOTE]
public void startVideoThread(){
try
{
[I]
[COLOR="Red"]player = Manager.createPlayer("capture://video");
player.realize();
control = (VideoControl)player.getControl("VideoControl");
control.initDisplayMode(VideoControl.USE_DIRECT_VIDEO,Display.getDisplay(this).getCurrent());
control.setVisible(false);
player.start();
}
catch(Exception e)
{
}[/COLOR][/I]
[I]
try
{
raw = control.getSnapshot("encoding=bmp");
image = Image.createImage(raw, 0, raw.length);
raw2 = control.getSnapshot("encoding=bmp");
image2 = Image.createImage(raw2, 0, raw2.length);
// some processing is done here
cuMVx=(cuMVx+vH)/2;
cuMVy=(cuMVy+vV)/2;
int x = testAppCanvas.positionX; int newPosX = cuMVx+x;
int y = testAppCanvas.positionY; int newPosY = cuMVy+y;
testAppCanvas.change(newPosX,newPosY);
Display.getDisplay(this).setCurrent(testAppCanvas);[/I]
}
catch(Exception exc)
{
}
player.close();
player = null;
control = null;
}
}[/QUOTE]
Kindly revert with some more information
Re: slow update of canvas - 30s wait
raj_J2ME,
i need snapshot from camera to perform some processing for the new location of the square.
ingsaurabh,
i applied what u suggest, and it works! thanks a lot.