Discussion Board

Results 1 to 2 of 2

Hybrid View

  1. #1
    Registered User Midori.Ryuu's Avatar
    Join Date
    Oct 2012
    Posts
    1
    Hello all. The app I'm working gives the user the ability to open images from the phone to send using J2ME.

    The problem is, when an image size is too large, the app throws an out of memory exception.

    I'm opening the images using the File API.

    Code:
    FileConnection fc = (FileConnection) Connector.open("file://localhost/" + currDirName + fileName);
    if (!fc.exists()) {
        throw new IOException("File does not exists");
    }
    InputStream fis = fc.openInputStream();
    Image im = Image.createImage(fis);
    fis.close();
    A second method I tried using
    Code:
    FileConnection fc = (FileConnection) Connector.open("file://localhost/" + currDirName + fileName);
    if (!fc.exists()) {
        throw new IOException("File does not exists");
    }
    InputStream fis = fc.openInputStream();
    
    ByteArrayOutputStream file = new ByteArrayOutputStream();
    int c;
    
    byte[] data = new byte[1024];
    
    while ((c = fis.read(data)) != -1) {
        file.write(data, 0, c);
    
    }
    
    byte[] fileData = null;
    fileData = file.toByteArray();
    
    fis.close();
    fc.close();
    file.close();
    Image im = Image.createImage(fileData, 0, fileData.length);
    I was wondering if there is any API that enables me to resize the image using the phone's memory, before loading it into my app?

    Currently I have this temporarily solved by calling platformRequest(), but the problem is I can't alter the photo photo viewer UI to add a "send" command which would upload the image to the server. (even if it's still a large size)

    I was wondering if there is a way to alter this?
    Last edited by Midori.Ryuu; 2012-10-02 at 10:16.

  2. #2
    Nokia Developer Moderator petrib's Avatar
    Join Date
    Mar 2003
    Posts
    9,413
    Read and sent the contents of the file (doesn't matter whether the bits are a photo or something else) in parts. In other words, do not try to read the whole file to memory at once (you don't need an in-memory copy of the image to send it to a server).

Similar Threads

  1. Out of memory error when reading image in phone's memory card
    By sundayokpokor in forum Mobile Java General
    Replies: 10
    Last Post: 2012-06-07, 17:28
  2. Image caching solutions
    By iparrot in forum Mobile Java General
    Replies: 5
    Last Post: 2010-12-30, 15:32
  3. Invalid jar error -- all solutions tried !
    By raxitsheth in forum Mobile Java General
    Replies: 4
    Last Post: 2010-01-10, 14:34
  4. out of memory error in image manipulation
    By vdx in forum Mobile Java Media (Graphics & Sounds)
    Replies: 4
    Last Post: 2009-04-13, 13:30
  5. large image solutions
    By ooooooo in forum Mobile Java General
    Replies: 1
    Last Post: 2004-01-14, 18:35

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved