×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    38

    problem occuring when the image is added on the canvas

    Hi Frens,


    I have implemented canvas class in j2me in that i have added image of specified size
    on screen.when i am running that application on device first of all white screen is
    appearing and then image is displayed after 1 sec.

    So can anyone please tell me that what is the reason and how to sort out
    this problem so that after launching the application image shud be displayed
    not the screen.

    Thanks-
    Ritu Singh

  2. #2
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: problem occuring when the image is added on the canvas

    Hello,

    When you will click the icon of the app that have install on device, it will start loading the resources whatsoever you have load in the code. So that may take few milliseconds or even few seconds, that depends upon the resources that you are trying to load. If the resources are too heavy in size then it will show the while screen till the time loading is complete.

    @ please share the widthxheight of the image and how many images are loading?
    @ what is the size of the image in KB, or the total size of all the images?
    @ on which device are you testing?
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  3. #3
    Registered User
    Join Date
    Dec 2009
    Posts
    38

    Re: problem occuring when the image is added on the canvas

    thanks for your quick reply....
    i am sending you the code please tel me
    how to resolve this issue.
    Here is the code and i am testing it on n-86 device.
    height and width is 320*388
    and the size of the image is 131 kb.

    package hello;
    import java.util.Timer;
    import java.util.TimerTask;
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.lcdui.game.GameCanvas;



    public class Midlet extends MIDlet
    {
    private Display display;
    private MyCanvas canvas;
    //private MyCanvas1 canvas1;


    public Midlet()
    {
    display= Display.getDisplay(this);
    canvas=new MyCanvas();
    //canvas1=new MyCanvas1();

    }//end of ImmutableImageExample



    public void startApp()
    {
    display.setCurrent(canvas);





    }//end of startApp

    public void pauseApp(){
    }

    public void destroyApp() {
    try {
    destroyApp(true);
    } catch (MIDletStateChangeException ex) {
    ex.printStackTrace();
    }
    notifyDestroyed();
    }

    public void exitMIDlet()
    {

    }//end of exitMIDlet

    protected void destroyApp(boolean unconditional) throws MIDletStateChangeException {
    throw new UnsupportedOperationException("Not supported yet.");
    }

    class MyCanvas extends Canvas
    {


    private Image objBKGImage = null;

    public MyCanvas()
    {
    // super(true);




    }







    public void paint(Graphics g)
    {


    int iViewH = this.getHeight();
    int iViewW = this.getWidth();



    // load the background image
    if (objBKGImage== null)
    {
    try
    {

    objBKGImage = Image.createImage("/aa.png");

    objBKGImage = CreateScaledImage(objBKGImage, iViewW, iViewH);

    } catch (Exception ex)
    {
    ex.printStackTrace();
    }
    }



    // draw background
    if (objBKGImage!= null)
    g.drawImage(objBKGImage,
    (int)iViewW / 2,
    (int)iViewH / 2,
    Graphics.VCENTER | Graphics.HCENTER );

    }
    public Image CreateScaledImage( Image imgOldImage, int iNewWidth, int iNewHeight )
    {

    Image imgNewImage = null;
    final int iOldWidth = imgOldImage.getWidth();
    final int iOldHeight = imgOldImage.getHeight();

    int iOldRGBArray[] = new int[iOldWidth * iOldHeight];

    imgOldImage.getRGB( iOldRGBArray, 0, iOldWidth, 0, 0, iOldWidth, iOldHeight);

    int iNewRGBArray[] = new int[iNewWidth * iNewHeight];

    for (int yy = 0; yy < iNewHeight; yy++)
    {
    int dy = yy * iOldHeight / iNewHeight;

    for (int xx = 0; xx < iNewWidth; xx++)
    {
    int dx = xx * iOldWidth / iNewWidth;

    iNewRGBArray[(iNewWidth * yy) + xx] = iOldRGBArray[(iOldWidth * dy) + dx];
    }
    }

    imgNewImage = Image.createRGBImage(iNewRGBArray, iNewWidth, iNewHeight, true);

    return imgNewImage;

    }
    }
    }

  4. #4
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: problem occuring when the image is added on the canvas

    Hi,
    First of all we would like to know the total size of the images that you are loading.
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  5. #5
    Registered User
    Join Date
    Dec 2009
    Posts
    38

    Re: problem occuring when the image is added on the canvas

    thanks for ur reply....

    the size of the image which i am loading is 131 kb.


    thanks-
    ritu

  6. #6
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: problem occuring when the image is added on the canvas

    Hello,
    You are doing the things a bit wrong,
    You are loading the image in the paint method. Kindly load the images always in the canvas constructor.
    Kindly have a look over the code here,
    http://www.java2s.com/Code/Java/J2ME...eonacanvas.htm
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  7. #7
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: problem occuring when the image is added on the canvas

    Quote Originally Posted by ritusingh View Post
    thanks for ur reply....

    the size of the image which i am loading is 131 kb.


    thanks-
    ritu
    Though It is heavy image. however you try the code over the link that I gave before,and let us know whether that was helpful to you,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  8. #8
    Registered User
    Join Date
    May 2007
    Posts
    91

    Re: problem occuring when the image is added on the canvas

    hello ritusingh,
    On device it is taking notable time because of

    Code:
    objBKGImage = CreateScaledImage(objBKGImage, iViewW, iViewH);




    Amit

  9. #9
    Registered User
    Join Date
    Dec 2009
    Posts
    38

    Re: problem occuring when the image is added on the canvas

    yes thanks for your suggestion.....
    this one worked out.

    Ritu

Similar Threads

  1. load image problem
    By Pmarcoen in forum Mobile Java Media (Graphics & Sounds)
    Replies: 2
    Last Post: 2009-08-23, 06:19
  2. Problem setting image on button
    By marstelecom in forum Mobile Java Games
    Replies: 0
    Last Post: 2009-08-12, 06:22
  3. Modules required :)
    By neil.young in forum Python
    Replies: 20
    Last Post: 2009-06-07, 11:35
  4. Problem with sending image
    By ckt in forum Symbian C++
    Replies: 5
    Last Post: 2007-01-03, 08:27
  5. scrolling an image larger than the canvas size problem
    By noobprogrammer in forum Mobile Java General
    Replies: 4
    Last Post: 2006-11-20, 03:20

Posting Permissions

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