×

Discussion Board

Results 1 to 4 of 4

Thread: png and jpg

  1. #1
    Registered User
    Join Date
    Jun 2005
    Posts
    3

    png and jpg

    I have a problem...i get a jpg image from Internet and then i try to show it in a canvas.
    Off course this method don't work!
    I think that the problem is in the metodh drawImage that don't support the jpg format.

    Anyone can tell me how to get a solution for my problem?

    It's possible to convert jpg to png?

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    3
    the code I used is this....




    import java.io.*;
    import javax.microedition.io.*;
    import javax.microedition.lcdui.Image;
    import javax.microedition.rms.*;

    public class Connessione extends Thread {
    ContentConnection c = null;
    InputStream iStrm=null;
    String url="";
    //byte imageData[];
    MyCanvas can=null;
    WBL m=null;
    Image im=null;

    public Connessione(MyCanvas c,String str,WBL ma){
    if(str.length()>0){
    url=str;
    }else{
    url="http://www.abc.com/test.jpg";
    }
    can=c;
    m=ma;
    }

    public void run(){
    System.out.println("run");
    try{
    c = (ContentConnection)Connector.open(url);
    iStrm = c.openInputStream();
    im = Image.createImage(iStrm);
    } catch(Exception e){
    System.out.println("errore connesione al web:"+e);
    }

    try{
    c.close();
    }catch( Exception e){
    System.out.println("ecc");
    }
    System.out.println("Fine caricamento");
    //m.al.setTimeout(9900);
    //m.attendi(1);
    can.CreaImm(im);

    }

    }


    in this way the size of the image is 0...
    i tried also to use this method=>
    import java.io.*;
    import javax.microedition.io.*;
    import javax.microedition.rms.*;

    public class Connessione extends Thread {
    ContentConnection c = null;
    DataInputStream iStrm=null;
    String url="";
    byte imageData[];
    MyCanvas can=null;
    main m=null;

    public Connessione(MyCanvas c,String str,main ma){
    if(str.length()>0){
    url=str;
    }else{
    url="http://www.lanponet.it/allarm.jpg";
    }
    can=c;
    m=ma;
    }

    public void run(){

    try{
    c = (ContentConnection)Connector.open(url);
    iStrm = c.openDataInputStream();
    }
    catch(Exception e){
    System.out.println("errore connesione al web:"+e);
    }

    try{
    int length = (int) c.getLength();
    imageData = new byte[length];
    iStrm.readFully(imageData);
    }
    catch(Exception e){
    System.out.println("errore lettura immagine da web:"+e);
    }


    try{
    RecordStore rs = RecordStore.openRecordStore("immagini3", true );
    System.out.println(rs.getNumRecords());
    if(rs.getNumRecords()>0)
    {
    rs.setRecord(1,imageData,0,imageData.length);
    System.out.println("set");
    }
    else
    {
    rs.addRecord(imageData,0,imageData.length);
    System.out.println("add");
    }
    System.out.println("Dim da memorizzare:"+imageData.length);
    rs.closeRecordStore();
    }
    catch(Exception e){
    System.out.println("Errore salvataggio:"+e);
    }

    try{
    c.close();
    }catch( Exception e){
    }
    m.al.setTimeout(100000);
    m.attendi(1);
    can.CreaImm();
    }

    }
    ...
    ...
    ...
    ...
    ...
    ...
    public void CreaImm(){
    try{

    RecordStore rs = RecordStore.openRecordStore("immagini3", true );
    imageData=new byte[rs.getRecordSize(1)];
    rs.getRecord(1,imageData,0);
    rs.closeRecordStore();
    }
    catch(Exception e){
    System.out.println("Errore lettura da memoria:"+e.toString());
    }

    try {
    System.out.println("Dim da visualizzare:"+imageData.length);
    im = Image.createImage(imageData,0,imageData.length);
    } catch (Exception e) {
    System.err.println("Non riesco a caricare"+e);
    }
    rimpicciolisci();
    }
    ...
    ...
    ..
    but in this way it gives me an IllegalArgumentException

  3. #3
    Registered User
    Join Date
    Jan 2005
    Location
    Germany / Bavaria
    Posts
    10
    Well, I think the JPEG Format is generally supported... I never had problems drawing a JPEG. Why don't u use the createImage("/.../yourJPEG.jpg") method to create it?

  4. #4
    Registered User
    Join Date
    Jun 2005
    Posts
    3
    The method createImage("/.../yourJPEG.jpg") is ok, the problem is that the image i have to use for my application is on a LAN network or on internet and to get it i have to use an httpConnetction or something similar, and then put the byte of the image into an array ...in that way my prog don't work.

Posting Permissions

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