×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Regular Contributor
    Join Date
    Sep 2009
    Posts
    84

    cant store images

    Midlet class
    Code:
       public void startApp()
         {
    Vector v = new Vector();
            v.addElement("aaaa");
            v.addElement("bbbb");
            v.addElement("cccc");
    
            NewClass1 nc = new NewClass1();
            Vector c = nc.getImages(v);
    
            OpenRecordStore("imagestore");
            for (int i = 0; i < c.size(); i++)
             storeImage((Image)c.elementAt(i));
    
            CloseRecordStore();     
    }
    
    public void OpenRecordStore(String rmsNAme)
         {
            try
             {
                rs = RecordStore.openRecordStore(rmsNAme, true);
             }
    
            catch(Exception e){}
         }
    
        public void CloseRecordStore()
         {
            try
             {
                rs.closeRecordStore();
             }
    
            catch(Exception e){}
    
         }
        
        public void storeImage(Image image)
         {
            int width,height;
            try
             {
                System.out.println(rs.getNextRecordID());
                width = image.getWidth();
                height = image.getHeight();
                int imageData[] = new int[width*height];
                image.getRGB(imageData, 0, width, 0, 0, width, height);
                ByteArrayOutputStream outStream = new ByteArrayOutputStream();
                DataOutputStream dataOut = new DataOutputStream(outStream);
                for (int i = 0; i < imageData.length; i++)
                 dataOut.writeInt(imageData[i]);
                rs.addRecord(outStream.toByteArray(), 0, outStream.toByteArray().length);
                dataOut.close();
                outStream.close();
             }
    
            catch(Exception e) {}
         }
    NewClass1.java
    Code:
    import java.io.ByteArrayOutputStream;
    import java.io.DataInputStream;
    import java.util.Vector;
    import javax.microedition.io.Connector;
    import javax.microedition.io.ContentConnection;
    import javax.microedition.lcdui.Image;
    
    public class NewClass1
     {
        Vector data1;
    
        public NewClass1 ()
         {
            data1 = new Vector();
         }
    
        public Vector getImages(Vector data)
         {
            for (int i = 0; i < data.size(); i++)
             {
                try
                 {
                    ContentConnection connection = (ContentConnection) Connector.open("http://localhost/tutorial/images/" + data.elementAt(i) + ".jpg");
                    DataInputStream iStrm = connection.openDataInputStream();
                    ByteArrayOutputStream bStrm = null;
                    Image im = null;
    
                    byte imageData[];
                    int length = (int) connection.getLength();
                    if (length != -1)
                     {
                        imageData = new byte[length];
    
                        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();
                     }
    
                    im = Image.createImage(imageData, 0, imageData.length);
                    data1.addElement(im);
    
                    if (connection != null)
                     connection.close();
                    if (iStrm != null)
                     iStrm.close();
                    if (bStrm != null)
                     bStrm.close();
                 }
    
                catch (Exception e)
                 {
                    e.printStackTrace();
                 }
             }
    
            return data1;
        }
    }
    the result of print is 1,2,2. only the first image gets stored. i checked the images. i created a form inside the startapp method and appended every image into it. i was able to see them no problem. i didnt even have to cast the elements to Image (formx.append(data.elementAt(0));
    shouldnt it be 1 2 3? shouldnt i b able to store all the images? the sizes are small. 326 by 92 dimensions.
    i checked the size of data1. it downloaded all 3 images.
    if i try to print the details of the rms, i only get details for the first pic. the second one doesnt even get store. how come?
    these two classes arent my final version of course. i no it looks a bit ugly but im just putting everything together for you.

    Thank you.
    Last edited by WildHeart; 2011-01-10 at 05:29.

  2. #2
    Regular Contributor
    Join Date
    Sep 2009
    Posts
    84

    Re: cant store images

    ok new approach.

    Midlet
    Code:
    public void startApp()
         {
                   
            Vector v = new Vector();
            v.addElement("aaaa");
            v.addElement("bbbb");
            v.addElement("cccc");
            NewClass1 nc = new NewClass1();
            Vector c = nc.getCards(v);
         }

    NewClass1.java
    Code:
    import java.io.ByteArrayOutputStream;
    import java.io.DataInputStream;
    import java.io.DataOutputStream;
    import java.util.Vector;
    import javax.microedition.io.Connector;
    import javax.microedition.io.ContentConnection;
    import javax.microedition.lcdui.Image;
    import javax.microedition.rms.RecordStore;
    
    public class NewClass1
     {
        Vector data1;
        RecordStore rs;
    
        public NewClass1 ()
         {
            data1 = new Vector();
         }
    
        public Vector getImages(Vector data)
         {
            OpenRecordStore("imagestore");
            for (int i = 0; i < data.size(); i++)
             {
                try
                 {
                    ContentConnection connection = (ContentConnection) Connector.open("http://localhost/tutorial/images/" + data.elementAt(i) + ".jpg");
                    DataInputStream iStrm = connection.openDataInputStream();
                    ByteArrayOutputStream bStrm = null;
                    Image image = null;
    
                    byte imageData[];
                    int length = (int) connection.getLength();
                    if (length != -1)
                     {
                        imageData = new byte[length];
    
                        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();
                     }
                   image = Image.createImage(imageData, 0, imageData.length);
                    
                    System.out.println(rs.getNextRecordID());
                    //store
                    int width, height; 
                    width = image.getWidth();
                    height = image.getHeight();
                    int imageData1[] = new int[width*height];
                    image.getRGB(imageData1, 0, width, 0, 0, width, height);
                    
                    ByteArrayOutputStream outStream = new ByteArrayOutputStream();
                    DataOutputStream dataOut = new DataOutputStream(outStream);
                    for (int xi = 0; xi < imageData1.length; xi++)
                     dataOut.writeInt(imageData1[xi]);
                    rs.addRecord(outStream.toByteArray(), 0, outStream.toByteArray().length);
                    dataOut.close();
                    outStream.close();
    
                    data1.addElement(image);
    
                    if (connection != null)
                     connection.close();
                    if (iStrm != null)
                     iStrm.close();
                    if (bStrm != null)
                     bStrm.close();
                 }
    
                catch (Exception e)
                 {
                    e.printStackTrace();
                 }
             }
            
            CloseRecordStore();
    
            return data1;
        }
    
        public void OpenRecordStore(String rmsNAme)
         {
            try
             {
                rs = RecordStore.openRecordStore(rmsNAme, true);
             }
    
            catch(Exception e){}
         }
    
        public void CloseRecordStore()
         {
            try
             {
                rs.closeRecordStore();
             }
    
            catch(Exception e){}
    
         }
    }
    i figured id store soon as i got the image. this time it printed 1 2 then recordStorefullexception then 2 then recordStorefullexception
    how did it get full? o.o

    figured id do some research. one link said that emulator could be full. that didnt make sense. but then this link http://forums.netbeans.org/ntopic10720.html helped. it had instructions for me to follow. im running netbeans 6.9.1 i selected java tm micro edition then clicked on tools&extensions. but thts it. nothing was highlighted. selectable.
    Last edited by WildHeart; 2011-01-10 at 05:52.

  3. #3
    Regular Contributor
    Join Date
    Sep 2009
    Posts
    84

    Re: cant store images

    i got it to work. friend suggested i download wtk 2.5.2. it worked. same code. i had no idea sdk 3 was buggy o.o

  4. #4
    Super Contributor
    Join Date
    Mar 2005
    Location
    Paris
    Posts
    814

    Re: cant store images

    that totally makes sense, your images are _just_ 125 Ko big, so it is likely that the maximum size for a record store is less than twice that. on many blackberry before 2008, the limit was 64Ko.
    oh, and just a small good practice : never leave a catch block empty. never. ever.
    and you should check the available size of the record store before entering data.
    and you probably should not save images in RMS anyway

Similar Threads

  1. How to store the images in files
    By prathi in forum Symbian
    Replies: 4
    Last Post: 2010-12-15, 20:09
  2. retrive a images from the server and i want to store
    By narendrachinni in forum Symbian User Interface
    Replies: 3
    Last Post: 2009-09-02, 08:21
  3. [moved] Store and retrieve Images
    By Fye_08 in forum Mobile Java Media (Graphics & Sounds)
    Replies: 10
    Last Post: 2009-02-26, 16:07
  4. can we store images in XML
    By lakshmanraob in forum Mobile Java Tools & SDKs
    Replies: 2
    Last Post: 2005-10-03, 19:28
  5. How to store Images in RMS?
    By lightpop in forum Mobile Java General
    Replies: 5
    Last Post: 2005-02-07, 18:11

Posting Permissions

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