×

Discussion Board

Results 1 to 12 of 12
  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    2

    Question Downloading image on series 60 (6680)

    i try to download a png image from a server to my midlet.

    the download works, but i cant display the image!

    ...
    httpConnection = (HttpConnection)Connector.open(url);
    ...
    in = httpConnection.openInputStream();
    ...
    image = Image.createImage(in); // throws IoException

    a diffrent way is
    ...
    ByteArrayOutputStream byteArrayout = new ByteArrayOutputStream();
    byte[] buffer = new byte[ 5 * 1024 ];
    int read;
    while ( (read = in.read(buffer, 0, buffer.length) ) != -1 ) {
    byteArrayout.write( buffer, 0, read );
    }
    image = Image.createImage( byteArrayout.toByteArray(), 0, byteArrayout.toByteArray().length); // throws IllegalArgumentException



    how can i display a image that i downloaded on a 6680/6630???

    my firmware is
    v 3.04.11
    14-04-05
    RM-36

  2. #2
    Registered User
    Join Date
    Aug 2005
    Posts
    25

    Re: Downloading image on series 60 (6680)

    hi dippen,
    I am lakshman,I am also facing the same problem.I am also getting the IOException,and also the illegalArgumentException.
    If you find the solution for this problem,please let me know
    thanks in advance
    lakshman

  3. #3
    Regular Contributor
    Join Date
    Mar 2003
    Location
    Norway
    Posts
    63

    Lightbulb Re: Downloading image on series 60 (6680)

    Quote Originally Posted by lakshmanraob
    hi dippen,
    I am lakshman,I am also facing the same problem.I am also getting the IOException,and also the illegalArgumentException.
    If you find the solution for this problem,please let me know
    thanks in advance
    lakshman
    You might want to use an image format which is actually supported on your phone. Using the pure inputstream Image constructor works.

  4. #4
    Registered User
    Join Date
    Mar 2003
    Posts
    38

    Re: Downloading image on series 60 (6680)

    Please see the actual image bytes. I have found out some JPEG's are kind of "invalid"; they are missing some bytes according the JPEG spec.

    If the Image class throws IllegalArgumentException, this just means it cannot read the bytes and construct an Image out of them.

    I have fixed manually "out-of-spec" JPEG's by adding missing bytes in my code (from the beginning):

    byte[] missingBytes = new byte[] { (byte)0xFF, (byte)0xD8, (byte)0xFF, (byte)0xE0, (byte)0x00, (byte)0x10, (byte)0x4A, (byte)0x46, (byte)0x49, (byte)0x46, (byte)0x00, (byte)0x01, (byte)0x01, (byte)0x00, (byte)0x00, (byte)0x01, (byte)0x00, (byte)0x01, (byte)0x00 };

    This is just an example fix for JPEG's which throw this exception, not PNG's whatsoever. Then do some System.arraycopy'ing and voilá; you have ready byte array for Image class

    Best regards,

    -Samuli

  5. #5
    Nokia Developer Champion
    Join Date
    Mar 2005
    Location
    Paris
    Posts
    814

    Re: Downloading image on series 60 (6680)

    check the length of your buffer
    check the content of the image you download, there might be some conversion somewhere, i happened to face ??? instead of some undisplayable caracteres

  6. #6
    Registered User
    Join Date
    Oct 2005
    Posts
    12

    Re: Downloading image on series 60 (6680)

    Hi Guys,

    We are also having problems with images(MJPEG) not being able to be displayed on Nokia 6680 phones. We think it is a firmware issue because in previous firmware versions V2.39.140 (tested with Nokia 6630) the images can be displayed without problems. Therefore, it would be logical that newer firmware versions can also support mjpeg, since most software are backward compatible;but it seems not to be the case.

    Can anyone at Nokia help us resolve this issue?

    Many telecom providers we are in discussion with are very interested in our solution but so far the only 3G phones that can sucessfully our MJPEG are motorola. They perfer to have the Nokia phones be able to display MJPEG also.

    Since motorola 3G phones (E1000. v975) can display MJPEG I am at a lost as to why Nokia 3G phones with the new firmware cannot.

    we alone cannot solve this problem. We need assistance from Nokia HQ.

  7. #7
    Registered User
    Join Date
    Nov 2005
    Posts
    2

    Re: Downloading image on series 60 (6680)

    Hi
    I'm also facing the same problem. I´m trying to download a png image from a server to my midlet. It works fine on the emulator, but when i run it on a nokia 3650 the createImage method throws an exception.

    I check the length of the buffer image and i notice that in the emulator the buffer length is 3283 bytes and in the nokia 3650 the buffer length is 201 bytes!
    Do you know why is this happen?
    Is there a limit of size for downloading data on nokia 3650?

    Thanks in advance.

  8. #8
    Nokia Developer Champion
    Join Date
    Mar 2005
    Location
    Paris
    Posts
    814

    Re: Downloading image on series 60 (6680)

    would you past the piece of code where you get the byte[] ?
    there might be a problem if you use a too large buffer, or if you use the method read(byte[]), which may result in your problem, i.e. truncated output

  9. #9
    Registered User
    Join Date
    Nov 2005
    Posts
    2

    Re: Downloading image on series 60 (6680)

    That it´s my code:

    Code:
                 HttpConnection conn = (HttpConnection)Connector.open(url,Connector.READ);
                            
                // HEADERS------------------------------------------------------
                conn.setRequestMethod( HttpConnection.GET );
                conn.setRequestProperty("User-Agent", 
                        "Profile/MIDP-1.0 Configuration/CLDC-1.0");
                conn.setRequestProperty( "Accept", "image/png" );
                conn.setRequestProperty("Content-Type", "image/png");
                
                if( conn!= null ) {
                    if ( conn.getResponseCode() == HttpConnection.HTTP_OK && 
                         conn.getType().toLowerCase().indexOf("image/png") != -1 )
                    {
                                    
                        DataInputStream iStrm = conn.openDataInputStream();
           
                        Image img = null;
                        byte [] imageData = null;
                        
                        int strmLength = (int) conn.getLength();
                        
                        if( strmLength == -1 )
                        {   // Reading from an HTTP 1.0 server or a chunked HTTP 1.1
                            ByteArrayOutputStream bStrm = new ByteArrayOutputStream();
                            int ch;
                            while ((ch = iStrm.read()) != -1)
                                bStrm.write(ch);
                            bStrm.flush();
                            imageData = bStrm.toByteArray(); 
                            bStrm.close();
                        }
                        else {
                            // Reading a Content-Length labeled payload
                            imageData = new byte[strmLength];
                            iStrm.readFully(imageData);
                        }
                        
                        midlet.formMainScreen.append("ImageData.length: "+imageData.length);
                        
                        try {    
                            img = Image.createImage(imageData, 0,  imageData.length); 
                        }catch(java.lang.IllegalArgumentException iae) {
                            writeMessage("Erro: ",
                                    "Ocorreu um erro ao criar a imagem...Illegal arg: " 
                                    +iae.getMessage());
                            
                        }catch(Exception e) {
                            writeMessage("Erro: ",
                                    "Ocorreu um erro ao criar a imagem..." +e);
                        }
                        finally {
                            if( iStrm != null ) iStrm.close();
                            if( conn  != null ) conn.close();
                            if( img   != null ) this.setMapImage(img);
                        }
    I know that the response from server is chunked because the strmLength = -1... It seems that on my phone (nokia 3650) it only opens the 1st chunk!

    Can you help me?

    thank you very much.

  10. #10
    Regular Contributor
    Join Date
    Feb 2006
    Posts
    112

    Re: Downloading image on series 60 (6680)

    Has anyone managed to accomplish this? I have managed to download a PNG image and got it working on s60 3rd edition devices, s60 2nd ed FP1 (3230), S40 2nd and 3rd edition.

    S60 2nd ed FP2 and FP3 are the ones causing a problem. I have tried with Nokia 6680 (FP2) and Nokia S60 2nd ed FP3 Emulator. Emulator says:

    java.lang.IllegalArgumentException: bad image format
    - javax.microedition.lcdui.Image.createImage(), bci=74

    .. when I try to create an image out of the data received. Every other phone displays the image without any problem. I have also checked that every byte of the image is received succesfully. Content-Length is defined in the HTTP header, since without it 6680 wouldn't read anything at all (another bug!).

    Here is the part where I read the data:

    Code:
             if( rc == HttpConnection.HTTP_OK ){
                  try {
                	  DataInputStream din = new DataInputStream(conn.openInputStream());
                	  data = new byte[(int) conn.getLength()];
                	  din.readFully(data);
                      din.close();
                      System.out.println("Received " + data.length + " bytes of image data.");
                    }
    .. and here is how I try to create the image:

    Code:
    	try {
    		  imgMap = Image.createImage(data, 0, data.length);
    	} catch (Exception e) {
    		e.printStackTrace();
    	}
    I really hope there is a solution to this, otherwise it's a major bug. Thank you for your time.

  11. #11
    Super Contributor
    Join Date
    Dec 2005
    Location
    Europe/Poland/Warsaw
    Posts
    1,699

    Re: Downloading image on series 60 (6680)

    hi pillar,
    can you try code from that post?
    http://discussion.forum.nokia.com/fo...89&postcount=6
    could be not related, but that's only other thread I've found with similiar error description,
    regards,
    peter

  12. #12
    Regular Contributor
    Join Date
    Feb 2006
    Posts
    112

    Re: Downloading image on series 60 (6680)

    peterblazejewicz:

    Thanks for the code tip. I tried it and it works on other phones, but still the same on 6680.

    I did some extra research and this is what I learned:

    My application connects to a php script that converts a jpeg to png, in order to make it work with my application. It then returns the png to the application.

    I came to the conclusion that it is my php code that is making jpeg->png conversion inbetween that is somehow making it a "bad image format" for those 2nd ed. phones like 6680. I managed to get it working with other png images without conversion, but not with the png that I need to get it working.

Similar Threads

  1. HELP: Mutable Image to Immutable Image?
    By rj_cybersilver in forum Mobile Java Media (Graphics & Sounds)
    Replies: 1
    Last Post: 2005-03-26, 09:58
  2. Series 40 - draw only a part of the image
    By ionutianasi in forum Mobile Java Media (Graphics & Sounds)
    Replies: 11
    Last Post: 2003-09-08, 04:25
  3. Series 60 Concept Emulator (SDK Beta 0.2 Linux) not working
    By mattbee in forum Mobile Java Tools & SDKs
    Replies: 1
    Last Post: 2003-06-10, 11:43
  4. Series 60Series 60 MIDP Concept SDK Beta 0.2 Linux bug?
    By kauppi in forum Mobile Java Tools & SDKs
    Replies: 3
    Last Post: 2003-04-07, 09:05

Posting Permissions

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