Results 1 to 2 of 2
  1. #1
    b12 is offline Member
    Join Date
    Apr 2009
    Rep Power

    Default Loading large images in JavaME

    Hi Everybody, Long time fan, first time caller. :D I didn't find anything in my search and hope that I have posted my question to the right place.

    I am hoping someone could help me determine how to display large image files without popping the memory when loading them. At risk of stating the obvious:rolleyes:, when I say popping the memory I mean getting a java.lang.OutOfMemoryError exception.
    So far when attempting to display images taken with an internal camera I have tried to use the MediaProcessor and ImageTransformControl however this method throws the aforementioned exception on the mediaProcessor.setInput() call with a large InputStream:
    Java Code:
     FileConnection fc = (FileConnection); 
     InputStream src = fc.openInputStream(); 
     MediaProcessor mp = null; 
     try { 
        mp = GlobalManager.createMediaProcessor(image/jpeg); 
        mp.setInput(src, MediaProcessor.UNKNOWN); //POP! 
        ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
        ImageTransformControl fc = (ImageTransformControl)mp.getControl( javax.microedition.amms.control.imageeffect.ImageTransformControl); 
        return Image.createImage(bos.toByteArray(), 0, bos.size());
    Another approach was to read the image in chunks, in attempts to resize the chunks then cat back together once all the pieces are loaded:
    Java Code:
      byte[] data = new byte[chunkSize]; 
      do { 
           int length =, 0, chunkSize); 
           Image img = Image.createImage(data, 0, chunkSize); 
    however an IllegalArgumentException is thrown due to the CreateImage method being unable to deccode the image chunk.:mad:

    Open to suggestions,

  2. #2
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Cambridge, UK
    Rep Power


    I *think* the chunking method will work, but you can't just have any old chunk size, otherwise you won't land on proper data boundaries.
    Alternatively, is there nothing you can do to reduce the size of the input beforehand? Have you tried increasing the JVM memory allowance?

Similar Threads

  1. Displaying large images
    By pir8ped in forum AWT / Swing
    Replies: 2
    Last Post: 01-21-2009, 10:20 PM
  2. JavaMe and native application interoperability
    By islamfunny in forum CLDC and MIDP
    Replies: 1
    Last Post: 10-27-2008, 10:58 PM
  3. Loading images in seperate packages?
    By Bibendum in forum New To Java
    Replies: 0
    Last Post: 03-02-2008, 11:43 PM
  4. Loading Images - Imp
    By Thulasiraman in forum Advanced Java
    Replies: 0
    Last Post: 01-28-2008, 10:33 AM

Posting Permissions

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