×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    36

    Appending images to the form.

    Hi All,

    I am finding it difficult to append images to the form.
    It always throws an exception. I mean the image does not get found I guess.

    Here is the code:
    -----------------
    ImageItem imageItem;
    {
    try
    {
    System.out.println ("Reached in try block");
    imageItem = new ImageItem ("MyImage", Image.createImage("pic.png"),ImageItem.LAYOUT_DEFAULT, "Test");

    fetchForm.append (imageItem);
    } catch (Exception e) {
    System.out.println ("Exception thrown while looking for image");
    }
    }
    ---------------

    I am using Eclipse 3.4 and SDK 3rd edition FP2. I am putting the image file in 'res' directory under project folder of eclipse. Though I am not sure if I am putting the image file at right place.
    Could someone please tell me what is the correct location to place image files?

    Thanks in advance
    Ak

  2. #2
    Registered User
    Join Date
    Sep 2007
    Location
    Bangalore
    Posts
    868

    Re: Appending images to the form.

    Hi,
    Can you try like this..
    imageItem = new ImageItem ("MyImage", Image.createImage("/pic.png"),ImageItem.LAYOUT_DEFAULT, "Test");

  3. #3
    Registered User
    Join Date
    Sep 2008
    Posts
    36

    Re: Appending images to the form.

    Yeah I tried with that as well. But it didnt work.
    I am getting the following exception:

    java.io.IOException: Cannot read /pic.png

  4. #4
    Registered User
    Join Date
    Sep 2008
    Posts
    36

    Re: Appending images to the form.

    Is there any limit on image size? If yes what is the max sized allowed?

  5. #5
    Registered User
    Join Date
    Sep 2008
    Posts
    36

    Re: Appending images to the form.

    Can some body please reply asap I need to know if urgently.

    Thanks

  6. #6
    Registered User
    Join Date
    Sep 2007
    Location
    Bangalore
    Posts
    868

    Re: Appending images to the form.

    Hi,
    IOException will come In createImage because of,

    IOException - if the resource does not exist, the data cannot be loaded, or the image data cannot be decoded

    Make sure that you are placing the image in the proper location .

  7. #7
    Registered User
    Join Date
    Sep 2008
    Posts
    36

    Re: Appending images to the form.

    I have tried putting image in various locations. for example - in 'res' folder, in top-level project folder and inside 'res' by creating a separate folder 'images'. Note that in the program I changed the path as per the image location.

    Unfortunately, that didnt work still.

  8. #8
    Nokia Developer Champion
    Join Date
    Sep 2007
    Posts
    915

    Re: Appending images to the form.

    If you are student then put sample code here so we can know what is wrong in it.

    -Kartik Trivedi

  9. #9
    Registered User
    Join Date
    Sep 2008
    Posts
    36

    Re: Appending images to the form.

    Here we go:
    ----------
    import java.io.IOException;

    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.Canvas;

    public class mainclass extends MIDlet {
    private Display displayScreen;


    public void startApp() {

    displayScreen = Display.getDisplay(this);
    Canvas test = new testCanvas ();
    displayScreen.setCurrent (test);

    }


    public void pauseApp() {
    /* Do nothing */
    }

    public void destroyApp(boolean unconditional) {
    notifyDestroyed();
    }







    static class testCanvas extends Canvas {
    static Image image;
    int count;

    public void paint(Graphics g) {
    int width = getWidth( );
    int height = getHeight( );
    // Fill the background using black
    g.setColor(0);
    g.fillRect(0, 0, width, height);
    // Load an image from the MIDlet resources
    if (image == null) {
    try {
    image = Image.createImage("/image1.png");
    } catch (IOException ex) {
    g.setColor(0xffffff);
    g.drawString("Failed to load image!", 0, 0, Graphics.TOP |
    Graphics.LEFT);
    return;
    }
    }
    switch (count % 3) {
    case 0:
    // Draw the image at the top left of the screen
    g.drawImage(image, 0, 0, Graphics.TOP | Graphics.LEFT);
    break;
    case 1:
    // Draw it in the bottom right corner
    g.drawImage(image, width, height, Graphics.BOTTOM |
    Graphics.RIGHT);
    break;
    case 2:
    // Draw it in the center
    g.drawImage(image, width/2, height/2, Graphics.VCENTER |
    Graphics.HCENTER);
    }
    count++;
    }
    }


    }

    ------------------
    And I have images in res folder under project folder.

  10. #10
    Super Contributor
    Join Date
    Apr 2003
    Location
    USA, CA
    Posts
    7,191

    Re: Appending images to the form.

    One more thing, check inside the jar file (it is basically a zip file, so you can open it with Winzip for example) and find out where the image files are located in there. Use the exact same path in your app.

    so if they are in /res directory, use /res/<imagename>

    Hartti

  11. #11
    Registered User
    Join Date
    Sep 2007
    Location
    Bangalore
    Posts
    868

    Re: Appending images to the form.

    Hi ,
    I tried your code I am able to draw the image...

    The Code I have tried is

    /*
    * mainclass.java
    *
    * Created on September 17, 2008, 12:00 PM
    */


    /**
    *
    * @author Bhanu
    * @version
    */
    import java.io.IOException;

    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.Canvas;

    public class mainclass extends MIDlet {
    private Display displayScreen;


    public void startApp() {

    displayScreen = Display.getDisplay(this);
    Canvas test = new testCanvas();
    displayScreen.setCurrent(test);

    }


    public void pauseApp() {
    /* Do nothing */
    }

    public void destroyApp(boolean unconditional) {
    notifyDestroyed();
    }







    static class testCanvas extends Canvas {
    static Image image;
    int count;

    public void paint(Graphics g) {
    int width = getWidth( );
    int height = getHeight( );
    // Fill the background using black
    g.setColor(0);
    g.fillRect(0, 0, width, height);
    // Load an image from the MIDlet resources
    if (image == null) {
    try {
    image = Image.createImage("/res/splash.png");
    } catch (IOException ex) {
    g.setColor(0xffffff);
    g.drawString("Failed to load image!", 0, 0, Graphics.TOP |
    Graphics.LEFT);
    return;
    }
    }
    switch (count % 3) {
    case 0:
    // Draw the image at the top left of the screen
    g.drawImage(image, 0, 0, Graphics.TOP | Graphics.LEFT);
    break;
    case 1:
    // Draw it in the bottom right corner
    g.drawImage(image, width, height, Graphics.BOTTOM |
    Graphics.RIGHT);
    break;
    case 2:
    // Draw it in the center
    g.drawImage(image, width/2, height/2, Graphics.VCENTER |
    Graphics.HCENTER);
    }
    count++;
    }
    }


    }

    Put your image dir along with your project path
    Ex: If you have a pacakea like A, B, and Resource folder

    It shold be apper like this
    I am using netbeans

    --Your ProjectName
    --A(your package)
    --B(Package)
    --res(your resource folder)
    --your .png file

    hope it will help you

  12. #12
    Registered User
    Join Date
    Sep 2008
    Posts
    36

    Re: Appending images to the form.

    I am using Eclispe and Nokia SDK.
    I checked the JAD file in my project folder and it does not contain any info on image file.
    I could not locate the jar file, can you please tell me where can find it? and if image file is not there then what should I do ?

    Thanks

  13. #13
    Registered User
    Join Date
    Sep 2008
    Posts
    36

    Re: Appending images to the form.

    Thanks a lot guys. It worked finally with lots of hassles.
    What I did was:
    In eclipse window - project-> properties
    Select Java build path
    and then Add Folder
    and then selcet images option there.
    Press OK.

    Create an images folder in project folder and put the images there in.

    But I would still like to know where the &*() final output jar file goes? For example if I want to know the content of jar file which is going to be loaded into the simulator's memory what should I do? where should I look for jar file after building the project?

    Thanks

  14. #14
    Super Contributor
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: Appending images to the form.

    This page should explain it.

  15. #15
    Registered User
    Join Date
    Sep 2008
    Posts
    36

    Re: Appending images to the form.

    Thank you.

Similar Threads

  1. second form not getting key events
    By krsunil in forum Symbian User Interface
    Replies: 3
    Last Post: 2008-12-10, 10:29
  2. Form troubles
    By matdodgson in forum Symbian User Interface
    Replies: 2
    Last Post: 2008-12-06, 10:49
  3. Weird Form behaviour on N73
    By Damo2k in forum Mobile Java Tools & SDKs
    Replies: 2
    Last Post: 2008-02-21, 15:43
  4. problems in creating multipage form
    By A.Vogel in forum Symbian User Interface
    Replies: 0
    Last Post: 2007-10-02, 08:16

Posting Permissions

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