×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    2

    Scrolling png image on canvas

    Hi,
    My problem is i want to scroll a image on canvas class to do that iam using a loop but the problem is the image is coming down at a time instead it must move down slowly,and if iam using threads to control paint method ,repaint is not calling paint.Its urgent if some one has idea regarding it pls helpme.

  2. #2
    Super Contributor
    Join Date
    Feb 2006
    Posts
    689

    Re: Scrolling png image on canvas

    Hi,
    Please check this link

    http://www.microjava.com/developer/f...ontent_id=1835

    Hope this will help you.

    Thanks
    Soku

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    2

    Re: Scrolling png image on canvas

    Hi,
    But it scroll only background image i want to scroll image on constant backroung.

  4. #4
    Super Contributor
    Join Date
    Mar 2006
    Posts
    516

    Re: Scrolling png image on canvas

    Hi raj,

    Are u referring to a ticker like image scrolling??

    U have to draw the image over the background image. Just change the x & y coordinate as u like. It will be better if u use a thread or a timer task.


    Wang

  5. #5
    Super Contributor
    Join Date
    Feb 2006
    Posts
    689

    Re: Scrolling png image on canvas

    Hi,
    If you want to move an image over a background that doesnt change,then just
    alter the X & Y co-ordinates of the image and just dont alter the background positions.

    Thanks
    Soku

  6. #6
    Super Contributor
    Join Date
    Nov 2003
    Location
    Bangalore , India
    Posts
    4,429

    Re: Scrolling png image on canvas

    Hi raj_ba03! Welcome to Nokia Discussion Boards!! :)

    Here is the code that will work fine for vertical scrolling of an image in the Res folder
    If you want to make horizontal scroll,
    change "g.drawImage(image,0,count,Graphics.TOP|Graphics.LEFT);" to g.drawImage(image,count,0,Graphics.TOP|Graphics.LEFT);

    Code:
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    
    public class TestScroll extends MIDlet
    {
    	TestCanvas tc = new TestCanvas();
    	public void startApp()
    	{
    		Display.getDisplay(this).setCurrent(tc);
    	}
    	public void pauseApp(){}
    
    	public void destroyApp(boolean bl){}
    }
    
    class TestCanvas extends Canvas implements Runnable
    {
    	Thread thread;
    	Image image;
    	int count;
    	int imageSplitHeight=10;
    
    	public TestCanvas()
    	{
    		try
    		{
    			image = Image.createImage("/testImg.png");
    		}catch(Exception e){System.out.println("image not found");}
    		thread = new Thread(this);
    		thread.start();
    	}
    
    	public void run()
    	{
    		while(true)
    		{
    			try
    			{
    				count++;
    				Thread.sleep(100);
    				repaint();
    			}catch(Exception e)
    			{
    			}
    		}
    	}
    public void paint(Graphics g)
    	{
    		g.setColor(200,200,200);
    		g.fillRect(0,0,getWidth(),getHeight());
    		g.drawImage(image,0,count,Graphics.TOP|Graphics.LEFT);
    	}
    }
    Hope this helps!

    Regards
    Gopal

    Ps: Tested in WTK2.3 Default Emulator.

Similar Threads

  1. HELP: Mutable Image to Immutable Image?
    By rj_cybersilver in forum Mobile Java Media (Graphics & Sounds)
    Replies: 1
    Last Post: 2005-03-26, 09:58
  2. PNG Image won't load
    By maaberge in forum Mobile Java General
    Replies: 1
    Last Post: 2003-11-16, 18:13
  3. Major problem with delegation to Canvas
    By bartekn in forum Mobile Java Media (Graphics & Sounds)
    Replies: 8
    Last Post: 2003-10-08, 17:46
  4. Image Menu with canvas
    By efeba in forum Mobile Java Media (Graphics & Sounds)
    Replies: 2
    Last Post: 2003-06-26, 11:33
  5. Managing PNG image Size
    By ramka001 in forum Mobile Java General
    Replies: 2
    Last Post: 2003-05-21, 17:54

Posting Permissions

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