×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    80

    j2me createImage(Inputstream stream) problem

    Hi all,

    I use lots of images in my project. I read them using an inputstream like that:

    PHP Code:
    Inputstream is getClass().getResourceAsStream(path);
    image Image.createImage(is); 
    But creating each image (the second line) takes more than 200 miliseconds and most of the time, more than 300 miliseconds. How can I reduce that long time. Or can I use any other method. May be other function ??
    Any idea???

    Thanks and regards.

  2. #2
    Super Contributor
    Join Date
    Mar 2005
    Location
    Paris
    Posts
    814

    Re: j2me createImage(Inputstream stream) problem

    what is the size of your images? on which device is that slow?

  3. #3
    Registered User
    Join Date
    Apr 2010
    Posts
    80

    Re: j2me createImage(Inputstream stream) problem

    The size of the images differ from 1 to 6 KBs. I am testing on Nokia 6120c .

    I tested like that:

    PHP Code:
    long t0,t1;
    t0 System.currentTimeMillis();
    image Image.createImage(is); 
    t1 System.currentTimeMillis(); 
    Then I took the difference t1-t0. So I saw the results. There are about 30 images and it takes about 6-7 seconds to open the application.

    Thanks and regards.

  4. #4
    Super Contributor
    Join Date
    Mar 2005
    Location
    Paris
    Posts
    814

    Re: j2me createImage(Inputstream stream) problem

    you can:
    1/ open your images in a seperated thread starting with the images you really need and opening the first screen as soon as the necessary images are ready
    2/ put all of your images in one bigger image, and use clip to draw the part of the big image matching the small image you need. it is heavier perform, but you load only one image, which should be much faster (start by measuring the time to load a big image to make sure it is worth it)

    also, how are compressed your images ? some compression may be longer to open.

  5. #5
    Registered User
    Join Date
    Apr 2010
    Posts
    80

    Re: j2me createImage(Inputstream stream) problem

    I will test 1 and 2. I do not know the compression type. But some images take only 30-40 miliseconds. I will search the difference between those images and turn you back.

    Thank you very much.
    Last edited by asifsanli; 2011-01-13 at 16:45. Reason: eksikti :)

  6. #6
    Registered User
    Join Date
    Apr 2010
    Posts
    80

    Re: j2me createImage(Inputstream stream) problem

    I look into the details of the images and I realized that they are same. I switched their names and rerun the application. their name was 2_0 and 2_1.
    The 2_1 image was opening in 200 ms and 2_0 in 20 ms. After I changed their names, result is the same. Namely the key point is not the image, their order. 2_0 was read in 200 ms and 2_1 in 20 ms. Is not that very surprising and interesting???

  7. #7
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: j2me createImage(Inputstream stream) problem

    Assuming the files are in the JAR, I recommend you pass the file name to createImage(), not an InputStream.

    Code:
    // No
    InputStream in = getClass().getResourceAsStream(filename);
    Image img = Image.createImage(in);
    
    // Yes!
    Image img = Image.createImage(filename);
    This may help devices that hold images outside the Java heap to manage memory more effeciently.

    njzk2's options "2" is usually the prefered way, especially for groups of related images (like animation frames). Also helps to reduce application size and memory footprint.

    By "compression type", I think njzk2 is asking if they're PNGs or JPEGs. PNGs may decompress faster.

    Remember that much of the loading time for a file in the JAR depends on finding the file in the first place. JAR files are not well designed for random access. Access time may depend on things like, how close the file is to the start of the JAR.

    Graham.

  8. #8
    Registered User
    Join Date
    Apr 2010
    Posts
    80

    Re: j2me createImage(Inputstream stream) problem

    njzk2's options "2" ?? If I put all images in one big image, then I will get a huge image. For example Now I have 30 images, each 60*60 pixels. If I combine them, I will have an image 30*60*60 pixels which is 108000 pixels.

    Especially S40 Nokia devices such as 6300 are unable to open huge images. May be most of the devices will display same problem.

    Or Did I understand you wrong?

    Thanks and regards.
    Last edited by asifsanli; 2011-01-15 at 09:05. Reason: eksikti :D

  9. #9
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: j2me createImage(Inputstream stream) problem

    An image of 108,000 pixels will need about 400k of heap, which is within the capabilities of all but the oldest Series 40 devices.

    However, you do not need to pack all the images into one. Pack 30 images in 3 images of 10 each, or 10 images of 3 each. Plenty of possibilities.

    Graham.

Similar Threads

  1. J2ME RecordStore Vs Inputstream
    By maheshsudha in forum Mobile Java Media (Graphics & Sounds)
    Replies: 1
    Last Post: 2009-11-03, 21:02
  2. Help need with a J2ME Video stream problem (-34 prefetch error)
    By Phoenix_Dfire in forum Mobile Java Media (Graphics & Sounds)
    Replies: 5
    Last Post: 2009-06-25, 12:57
  3. svg createImage from InputStream problem
    By xylia in forum Mobile Java Media (Graphics & Sounds)
    Replies: 0
    Last Post: 2009-03-20, 10:36
  4. Exception on SvgImage.createImage from an HTTP Stream ?
    By douville in forum Mobile Java General
    Replies: 7
    Last Post: 2006-06-16, 12:57
  5. createImage from Stream?
    By darcone in forum Mobile Java Media (Graphics & Sounds)
    Replies: 2
    Last Post: 2004-03-31, 15:26

Posting Permissions

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