DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 12 of 12

Thread: saving images in j2me

  1. #1
    Join Date
    Jul 2005
    Posts
    54

    saving images in j2me

    hi,
    i'm trying to do some image processing in j2me.in that i display one image in canvas and make that one as negative image and also display that negative image in the canvas.now i want to save that image.while using rms to store the image the rms stores the image that is already in the resource folder only.
    please tell me if any knows how to save the image.
    also i tried with file connection api in that i'm able to append a text data.but don't know how to store the image.onemore condition while using is fileconnection is supported by CLDC1.1 only this configuration is rare in mobiles.
    please anyone knows the solution then help me
    thanx a lot in advance

  2. #2
    Join Date
    Nov 2003
    Posts
    4,118
    Where exactly is the image saved? On the mobile device itself or on the server? In the former case, you have to make sure that there's enough memory for storing that image. J2me has a different set of file I/O apis but there is a set of classes for creating and appending data to a file.
    Danny Kalev

  3. #3
    Join Date
    Jul 2005
    Posts
    54
    thanx for ur reply danny
    i want to save the image within the phone memory itself(like that Mypictures folder).
    u specified that set of classes for creating and appending data to a file whether u r specifying that fileconnection api's or other than that.if fileconnection means only CLDC1.1 supports fileconnection but most of the mobiles supports only CLDC1.0.
    i want to implement mmy appln.in mobile that''s y asking asking this.if u know that set of classes other than Fileconnection means please then tell me what r they and how to use that with j2me.
    thanx a lot for ur response.

  4. #4
    Join Date
    Nov 2003
    Posts
    4,118
    IF you must stick to CDLC, then you really have to use a workaround. CDLC 1.0 doesn't support file I/O at all, becuase it's used on devices that may not support file systems. Instead, you can store the data in memory, say buy saving it as a byte array or as a string. If the file contains an image, you can also store the pixels in an object that contains a byte array. This isn't easy in Java (that's why I prefer C/C++ -- languages that don't twist your arm and force you to use OO concepts) but it's doable.
    Danny Kalev

  5. #5
    Join Date
    Jul 2005
    Posts
    54
    thanx danny
    i'm developing one appln in j2me doing some image processing.i wnat to read the image that is stored in phone memoryi.e., where v store the picture that is captured usign camera.i'm usign the file connection api.In that i'm usign Connector.open() method to specify the path.i don't know to specify thephone memory's path.can u tell me the path to access the images that stored in phone's memory.i'm using sun'semulator

  6. #6
    Join Date
    Sep 2005
    Posts
    6
    Laxmi, can you tell me. Is there any specific reason for storing the captured image in file. Can't you store the same thing in a record store.

    Cheers!!!
    Ravi

  7. #7
    Join Date
    Jul 2005
    Posts
    54
    hi,
    the reason for saving the image in file is i'm reading the image stored in the mobile memory n doing image processing in tht.If i want to send tht processed image to one of my frd thru MMS then i think it easy for me to get the image from the file other than frm the recordstore.

  8. #8
    Join Date
    Dec 2006
    Posts
    1
    laxmi,
    I m also facing the same problem. I m developing an application for iDEN devices. This application needs to read images that are located in teh phone memory of the device. I can access the images in the SD card of the device. I hav used the file connection API for accessing the SD Card. But when i tried to access the root directory, the application automatically terminates. I don't know the corret path to the phone memory of the device. Please I need ur help.

  9. #9
    Join Date
    Feb 2007
    Posts
    1
    hello
    i have a project to detrmine the mobile position and give a map for it
    i need some J2me code that help me to read from the mobile memory SIM
    and send the info to a server
    pleas send a replay if u have any thing to help or know a site where i can find some thing for my project
    thankx to all

    " the best world is that one we live in "

  10. #10
    Join Date
    Oct 2007
    Posts
    2

    image into from rms

    hi,

    im trying to store and load image from rms the code follows .....
    Code:
    import javax.microedition.rms.*;
    import javax.microedition.rms.RecordStoreException;
    
    import javax.microedition.midlet.MIDlet;
    import javax.microedition.lcdui.*;
    import java.io.*;
    public class RMSImage extends MIDlet 
    {Form frm=null;
      private Display display;
    RecordStore rs;
    //int rnum;
    public RMSImage(){
      
    				rs=null;
     
    				//	 InputStream is=null;
    				display = Display.getDisplay(this);
    frm = new Form("Imageshow");
     
     int recnum=save();
     //System.out.println("djfghfgjh fd");
     load(recnum);
     
    }
    
    public void startApp(){
    
      
    
           try{
    		   rs=RecordStore.openRecordStore("imagefile",true); 
    		   System.out.println("record store created");
    			
    	  }
    	 
    	 catch(RecordStoreException r){r.printStackTrace();}
    	display.setCurrent(frm);
    	
    	}
    
    public int save(){
      int rnum=0;
      try{
    		   rs=RecordStore.openRecordStore("imagefile",true); 
    		   
     // System.out.println(imgdata);
      try{
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      DataOutputStream dos = new DataOutputStream(baos);
    byte data[]= null;
    		try{
    				System.out.println("hi");
    			DataInputStream dis = new DataInputStream(this.getClass().getResourceAsStream("/Duke.png"));
    	          
    	          System.out.println("check for image length");
    	       /* for(int j=0;j<3524;j++){ System.out.println("loop entering");data[j] = dis.readByte();System.out.println(data.length);
    	        
    	        	System.out.println("datalength"+data.length);
    	        }
      		 for (int i = 0; i < data.length; i++) 
    		{*/
    		
    		for(int j=0;j<2869;j++){
    			//System.out.println("print iimage"+j);
    		dos.writeByte(dis.readByte());}
    	
    	//	}
    	       	 }
    		catch(Exception e){System.out.println(e);}
    		
       //System.out.println(imgdata);
       int x=baos.toByteArray().length;
       rnum=rs.addRecord(baos.toByteArray(),0,baos.toByteArray().length); 
       System.out.println("length is"+x);
      
     
      }
      catch(RecordStoreNotFoundException rsnfe){}
      }
       catch(RecordStoreException rse){}
      catch(Exception ioe){}
      System.out.println("sucess");
     return rnum;
    	
    }
    
    
    public void load(int i){
    		System.out.println("one");
    		byte imagearray[]=null;	
    	try{System.out.println("one");
    
        	ByteArrayInputStream bis = null;
        	DataInputStream dis = null;
     	
     			 System.out.println("one");
    		try{
          	System.out.println("one");
            	rs = RecordStore.openRecordStore("imagefile", false);
            	bis = new ByteArrayInputStream(rs.getRecord(i));
            	dis = new DataInputStream(bis);        	
              	System.out.println("one1");
            	for(int k=0;k<2869;k++)
            	{
            	System.out.println("one");
            	imagearray[k]=dis.readByte();
            	System.out.println("one");
            //	System.out.println(dis.readByte());
            	}
            
          	          
    			System.out.println("record size is"+rs.getSize());
    		
    			 }catch(RecordStoreException e){}
    			 }catch(IOException e){}
    //System.out.println(data.length);
    //DataInputStream in = new DataInputStream()
    try{
    Image.createImage(imagearray,0,rs.getSize());
    }catch(Exception e){}
    
    
    	
    	}
      public void pauseApp(){}
      public void destroyApp(boolean flag){
      //System.out.println(save());
      }
    
    }

    but i cudnt
    cud u help me out
    Last edited by Hack; 10-26-2007 at 07:37 AM. Reason: Added Code Tags

  11. #11
    Join Date
    Oct 2007
    Posts
    4
    I am also in ur loop to need it. But storing image into RMS and retrieving is not the big deal.Application is to get rid out the image from either internal mem or external mem of the mobile.So what will be the generic path of the image shold we give to read by use of file connection API? - or else
    Process 1. Do we need to run one seperate application from the "X" MIDlet suit to store the image into RMS
    Process 2.Then we can retrieve the image from another midlet in the same suit for our further process.

    I am rude out of knowledge, anyone save me to get out of this.
    Last edited by mmdnazar; 10-29-2007 at 12:27 AM.

  12. #12
    Join Date
    Oct 2007
    Posts
    2
    here i have to get the img thru getClass().getResource()...
    irrespective of another midlet..
    if u find in dat vay cud u plz reply me

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center