Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User agajewski's Avatar
    Join Date
    Jan 2005
    Posts
    15
    Hello,

    If I have a PNG image on my server, how do I go about downloading it and placing the image into my midp application? Mainly the part of reading the image over the http interests me, if its even possible.

  2. #2
    Registered User cdoewarrior's Avatar
    Join Date
    Sep 2005
    Posts
    11
    I have tried this once converting the image into Base64. What I did is encrypted the image on the server side into Base64 code and then after reading it into my midlet decrypted it back.
    It worked for me.

    All the very best.

  3. #3
    Nokia Developer Champion raj_J2ME's Avatar
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,314
    Hi,
    This is the code you can work upon..This will download and save the image in yr application..
    any query will be answered...


    *-------------------------------------------------*/
    private Image getImage(String url) throws IOException
    {
    ContentConnection connection = (ContentConnection) Connector.open(url);

    // * There is a bug in MIDP 1.0.3 in which read() sometimes returns
    // an invalid length. To work around this, I have changed the
    // stream to DataInputStream and called readFully() instead of read()
    // InputStream iStrm = connection.openInputStream();
    DataInputStream iStrm = connection.openDataInputStream();

    ByteArrayOutputStream bStrm = null;
    Image im = null;

    try
    {
    // ContentConnection includes a length method
    byte imageData[];
    int length = (int) connection.getLength();
    if (length != -1)
    {
    imageData = new byte[length];

    // Read the png into an array
    // iStrm.read(imageData);
    iStrm.readFully(imageData);
    }
    else // Length not available...
    {
    bStrm = new ByteArrayOutputStream();

    int ch;
    while ((ch = iStrm.read()) != -1)
    bStrm.write(ch);

    imageData = bStrm.toByteArray();
    bStrm.close();
    }

    // Create the image from the byte array
    im = Image.createImage(imageData, 0, imageData.length);
    }
    finally
    {
    // Clean up
    if (iStrm != null)
    iStrm.close();
    if (connection != null)
    connection.close();
    if (bStrm != null)
    bStrm.close();
    }
    return (im == null ? null : im);
    }
    Thnxs
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

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