×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Jun 2007
    Posts
    10

    show image on the form from memory

    Hello everyone, I am trying to show a image form the mobile memory on the form, but it does not work ,please help me to see what is the problem.
    thanks
    public class Slidelet extends MIDlet
    {
    static Slidelet instance;
    SlideEngine engine = null;
    InputStream is = null;
    byte[] slide;
    Image img = null;
    private Image image1=null;
    private static final int CHUNK_SIZE= 1024;
    private Image currentImage = null;
    Image photo = null;

    public Slidelet()
    {
    instance = this;
    }
    public void startApp()
    {
    engine = new SlideEngine( Display.getDisplay(this ) );
    Form f1 = new Form( "Slide 1");
    f1.append( "This is slide number 1" );
    photo=displayImage();
    f1.append(new ImageItem("", photo, ImageItem.LAYOUT_TOP, null));
    Form f2 = new Form( "Slide 2");
    f2.append( "This is slide number 2" );
    Form f3 = new Form( "Slide 3");
    f3.append( "This is slide number 3" );
    engine.addSlide( f1, 2000 );
    engine.addSlide( f2, 2000 );
    engine.addSlide( f3, 2000 );
    engine.startShow();
    }
    public void pauseApp()
    {
    }
    public void destroyApp(boolean unconditional)
    {
    }
    public static void quitApp()
    {
    instance.destroyApp(true);
    instance.notifyDestroyed();
    instance = null;
    }
    public Image displayImage()
    {
    try
    {
    FileConnection fileConn =
    (FileConnection)Connector.open("file:///root1/1.png");
    InputStream fis = fileConn.openInputStream();
    long overallSize = fileConn.fileSize();
    int length = 0;
    byte[] imageData = new byte[0];
    while (length < overallSize)
    {
    byte[] data = new byte[CHUNK_SIZE];
    int readAmount = fis.read(data, 0, CHUNK_SIZE);
    byte[] newImageData = new byte[imageData.length + CHUNK_SIZE];
    System.arraycopy(imageData, 0, newImageData, 0, length);
    System.arraycopy(data, 0, newImageData, length, readAmount);
    imageData = newImageData;
    length += readAmount;
    }
    fis.close();
    fileConn.close();
    if (length > 0)
    {
    currentImage = Image.createImage(imageData, 0, length);
    }
    }
    catch (Exception e)
    { }
    return currentImage;
    }
    }






    public class SlideEngine
    {
    Display display;

    Vector sequence; // the vector hold the sequence of slides and time

    Thread thread;
    Timer timer;

    /**
    * Constructor.
    * take Display object as initialize parameters
    * @param d
    */
    public SlideEngine( Display d )
    {
    display = d;
    sequence = new Vector();
    }

    /**
    * Add a slide to this engine.
    * @param slide the slide
    * @param t the time duration (in ms) this slide is shown on sreen
    */
    public void addSlide( Displayable slide, int t )
    {
    sequence.addElement( slide );
    sequence.addElement( new Integer(t) );
    }

    /**
    * Start the slide show.
    * This create a new thread (Timer thread) and display the sequence
    */
    public void startShow()
    {
    timer = new Timer();
    thread = new Thread( timer );
    thread.start();
    }

    /**
    * End the show.
    */
    public void endShow()
    {
    timer.done = true;
    }

    /**
    * This timer class execute the sequence.
    */
    class Timer implements Runnable
    {
    int time;
    boolean done;

    public void run()
    {
    done = false;
    int cur = 0; // index to sequence


    while ( !done && cur < sequence.size() )
    {
    Object o = sequence.elementAt( cur );
    System.out.println("sequence: "+o);
    if ( o instanceof Displayable )
    {
    // if the sequence element is a Displayable, then show it on screen
    Displayable d = (Displayable)o;
    display.setCurrent( d );
    } else if ( o instanceof Integer )
    {
    // if the sequence is a Integer, then pause for the duration of this number
    time = ((Integer)o).intValue();
    try
    {
    Thread.sleep( time );
    } catch (Exception e)
    {
    }

    }
    // advance to next sequence element
    cur++;
    }
    } // end of class
    }


    }

  2. #2
    Registered User
    Join Date
    Aug 2007
    Posts
    14

    Re: show image on the form from memory

    What is the problem exactly?

    I would suggest open an image, adding it to a Vector, then painting it onto a Canvas, and not use Forms at all. Use a second vector for the image titles. Then, have 2 Image objects to display on the Canvas. You could then animate (slide) the images on and off screen. It is more work, but the result is better I think.

  3. #3
    Registered User
    Join Date
    Jun 2007
    Posts
    10

    Re: show image on the form from memory

    the question is how to show image from the phone memory on the form......

Similar Threads

  1. image doesnt show
    By RamiX in forum Browsing and Mark-ups
    Replies: 2
    Last Post: 2007-08-16, 07:20
  2. how to show image/text info on the top of Form
    By aplyhj in forum Symbian User Interface
    Replies: 0
    Last Post: 2007-07-24, 11:05
  3. Is MIDP2.0 over Symbian OS slow?
    By epolitakis in forum Mobile Java Games
    Replies: 7
    Last Post: 2007-03-16, 09:32
  4. How to show a form...
    By jhiey in forum Symbian User Interface
    Replies: 1
    Last Post: 2005-05-24, 08:13
  5. image show on view
    By neerajsoni in forum Symbian User Interface
    Replies: 0
    Last Post: 2005-01-10, 12:52

Posting Permissions

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