×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Jul 2011
    Posts
    35

    Question problem in displaying image in j2me..please do look into my code once..............

    hi ,i just wrote a code to take a snapshot....but the picture i took is not fullyshown on the screen..please can help me editing the picture to the mobile screen size............


    hers my code....

    Code:
    import java.io.OutputStream;
    import javax.microedition.lcdui.*;
    
    import javax.microedition.io.Connector;
    import javax.microedition.io.HttpConnection;
    import javax.microedition.lcdui.Alert;
    import javax.microedition.lcdui.AlertType;
    import javax.microedition.lcdui.Display;
    import javax.microedition.lcdui.Image;
    import javax.microedition.lcdui.Item;
    import javax.microedition.media.Manager;
    import javax.microedition.media.MediaException;
    import javax.microedition.media.Player;
    import javax.microedition.media.control.VideoControl;
    import javax.microedition.midlet.MIDlet;
    import javax.microedition.midlet.MIDletStateChangeException;
    
    //import org.bouncycastle.util.encoders.Base64;
    
    
    public class cameratest2 extends MIDlet implements CommandListener {
    	Player player;
    	VideoControl videoControl;
    	
    	//loctest loc=new loctest();
    	byte image[];
    	Image img;
    	boolean check;
    	Display display;
    	Form form;
    	Command cmdexit=new Command("Exit",Command.EXIT,2);
    	Command cmdpicture=new Command("Snap",Command.SCREEN,1);
    	Command cmdshowvedio=new Command("Showvd",Command.SCREEN,1);
    	//HttpConnection connection = null;
    	OutputStream os = null;
    	//String url="http://118.102.148.86/gps2/post_sender.php";
    	
    	public cameratest2(){
    		display=Display.getDisplay(this);
    		form=new Form("capturing picture");
    		form.addCommand(cmdexit);
    		
    		form.addCommand(cmdshowvedio);
    		form.setCommandListener(this);
    		
    	}
       
    	public void initiliaze_camera(){
        	try{
        	player = Manager.createPlayer("capture://video");
        	player.realize();
        	//Grap the Video control and set it to the current display
        	videoControl = (VideoControl) (player.getControl("VideoControl"));
        	if (videoControl != null) {
        		form.append((Item) (videoControl.initDisplayMode(
        		VideoControl.USE_GUI_PRIMITIVE, null)));
        		}
        	//start camera
        	
        		if (player != null) {
        		player.start();
        		}
        		if (videoControl != null) {
        		videoControl.setVisible(true);
        		}
        	
        	}
        	catch (Exception e){
        		Alert alert=new Alert("Error page","Location not found.",null,AlertType.ERROR);
    			alert.setTimeout(Alert.FOREVER);
    			display.setCurrent(alert);
        	}
        	
      }
        
    	////take picture....
    	public void snapshot()throws Exception{
        	try {
        		image = videoControl.getSnapshot("encoding=jpeg&width=640&height=480");
        		img=Image.createImage(image, 0, image.length);
        		form.append(img);
        		
        		if (videoControl != null) {
        			videoControl.setVisible(false);
        			}
        			if (player != null) {
        			player.stop();
        			player.close();
        			}
        			display.setCurrent(form);
        	} catch (MediaException me) { 
        		check = false;
        		
        		}
        		if(!check){
        		image = videoControl.getSnapshot("encoding=png");
        		form.append(img);
        		if (videoControl != null) {
        			videoControl.setVisible(false);
        			}
        			if (player != null) {
        			player.stop();
        			player.close();
        			}
        			form.append(img);
        		}
        		
    	}
    	
    	
    	
    	//stop camera..
       /*public void stopcam(){ 		
        		try {
        			if (videoControl != null) {
        			videoControl.setVisible(false);
        			}
        			if (player != null) {
        			player.stop();
        			player.close();
        			}
        			} catch (MediaException me) {
        			//messageItem.setText("Media Exception: " + me.getMessage());
        				System.out.println("camera not closed");
        				Alert alert=new Alert("Error page","Location not found.",null,AlertType.ERROR);
        				alert.setTimeout(Alert.FOREVER);
        				display.setCurrent(alert);
        			} 
       }*/
    
        
    
    
    
    
    	protected void destroyApp(boolean arg0) {
    		// TODO Auto-generated method stub
    
    	}
    
    	protected void pauseApp() {
    		// TODO Auto-generated method stub
    
    	}
    
    	protected void startApp() throws MIDletStateChangeException {
    		display.setCurrent(form);
    		// TODO Auto-generated method stub
    
    	}
    
    public void commandAction(Command cmd,Displayable d){
    	if(cmd==cmdexit){
    		/*if (videoControl != null && player != null) {
    		   stopcam();
    			}*/
    		
    		destroyApp(true);
    		notifyDestroyed();
    		
    		}
    	else if(cmd==cmdpicture){
    		try{
    			
    		snapshot();
    		}catch(Exception e){}
    	}
    	else if(cmd==cmdshowvedio){
    		
    		try{
    			form.addCommand(cmdpicture);
    			form.removeCommand(cmdshowvedio);
    			
    			initiliaze_camera();
    			display.setCurrent(form);
    			
    			}catch(Exception e){}
    	}
    }
    }

  2. #2
    Super Contributor
    Join Date
    Nov 2003
    Location
    Bangalore , India
    Posts
    4,429

    Re: problem in displaying image in j2me..please do look into my code once............

    If you are looking to resize an image, I have came across this article http://www.developer.nokia.com/Commu...ges_in_Java_ME . But I havent tried it yet.

    Regards
    Gopal

  3. #3
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: problem in displaying image in j2me..please do look into my code once............

    While you are asking for some issues then this is always better to provide the exact and complete information related to the same. If you are taking the pics from the device camera then the size of the taken pic will always be larger then the size of the screen and you must have to rescale the same to the screen size of the device.
    Give a hot to the method provided by Bala, that must work.
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  4. #4
    Registered User
    Join Date
    Jul 2011
    Posts
    35

    Re: problem in displaying image in j2me..please do look into my code once............

    i solved it by adjusting the height and width...of the picture

Similar Threads

  1. please help me (image upload problem in j2ME).....
    By Azhagupandian in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2011-03-22, 20:22
  2. Displaying one image on top of another image in J2ME
    By amishra in forum Mobile Java General
    Replies: 13
    Last Post: 2008-11-17, 08:35
  3. Hi yuuca please look into this Dial code...
    By alokkumarsingh in forum Symbian
    Replies: 6
    Last Post: 2004-08-10, 12:54
  4. Ipv6 problem, please take a look at my code
    By rui_botelho in forum Symbian Networking & Messaging (Closed)
    Replies: 0
    Last Post: 2004-07-12, 17:28
  5. Simulating left soft key, Pls look in to my code
    By alokkumarsingh in forum Symbian
    Replies: 4
    Last Post: 2004-07-05, 13:47

Posting Permissions

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