Multimedia and Graphics
Log In  ·  Help
Jump to Page:   1
  Reply   Reply  

Take a picture on W7
Options    Options  
andber
New Member
Posts: 3
Registered: 07-13-2009


andber

Message 1 of 3

Viewed 142 times


Hi all, I have a problem on W7 device using the camera. When I use the following line: videoControl.setDisplayFullScreen(true); The camera preview is black, and don´t show the preview. If I comment this line works "fine"; I want the camera preview in fullscreen mode... Can you help me? Thanks in advance, Andrés.
Kudos!
11-03-2009 08:50 AM
 
  Reply   Reply  

Re: Take a picture on W7
Options    Options  
gator
Technical Expert
Posts: 137
Registered: 03-06-2009


gator

Message 2 of 3

Viewed 131 times


Hi,

 

We're sorry about that. Seems it is a bug. Because the MIDlet works fine without that line.

 

But could you send us the code snippet, then we'll check it for you.

 

Regards

 

Yu Feng

Kudos!
11-04-2009 06:06 PM
 
  Reply   Reply  

Re: Take a picture on W7
Options    Options  
andber
New Member
Posts: 3
Registered: 07-13-2009


andber

Message 3 of 3

Viewed 121 times


Hello,

Thanks for your reply. Here I am attaching the source code. Please let me know if somethings is wrong.

 

Thanks a lot,

Andrés.

 

 

import java.io.IOException;
import javax.microedition.lcdui.*;
import javax.microedition.media.*;
import javax.microedition.media.control.*;
import javax.microedition.midlet.MIDlet;
import javax.microedition.media.control.VideoControl;

public class VideoControlExample extends MIDlet implements CommandListener{
 private Display display;
    private Form form;
    private Command exit, back, capture, camera, Rungc;
    private Player player;
    private VideoControl videoControl;
    private Video video;
   
    public VideoControlExample() {
  display = Display.getDisplay(this);
  form = new Form("Capture Video");
        exit = new Command("Exit", Command.EXIT, 0);
        camera = new Command("Camera", Command.SCREEN, 1);
        Rungc = new Command("Rungc", Command.SCREEN, 1);
        back = new Command("Back", Command.BACK, 2);
        capture = new Command("Capture", Command.SCREEN, 3);       
        form.addCommand(camera);
        form.addCommand(Rungc);
        form.setCommandListener(this);
    }
   
    public void startApp() {       
        display.setCurrent(form);
    }
   
    public void pauseApp() {}
   
    public void destroyApp(boolean unconditional){
  notifyDestroyed();
 }
   
    public void commandAction(Command c, Displayable s){
  String label = c.getLabel();
        if (label.equals("Exit")){
            destroyApp(true);
        } else if (label.equals("Camera")) {
            showCamera();
        } else if (label.equals("Back"))
            display.setCurrent(form);
        else if (label.equals("Capture")) {
            video = new Video(this);
            video.start();
        }
        else if (label.equals("Rungc")){
         System.gc();
         form.append("FM: gc " + Runtime.getRuntime().freeMemory()/1000);
        }
    }
   
    public void showCamera(){
     try{
      form.append("encodings = " + System.getProperty("video.snapshot.encodings"));
      //form.append("FM: 1 " + Runtime.getRuntime().freeMemory()/1000);
         player = Manager.createPlayer("capture://video");
      // Con nokia probar lo de abajo:
      //player = Manager.createPlayer("capture://image");
            player.realize();           
            videoControl = (VideoControl)player.getControl("VideoControl");
            Canvas canvas = new VideoCanvas(this, videoControl);
            canvas.addCommand(back);
            canvas.addCommand(capture);
            canvas.setCommandListener(this);
            display.setCurrent(canvas);
            player.start();
            //form.append("FM: 2 " + Runtime.getRuntime().freeMemory()/1000);
        } catch (IOException ioe) {
         form.append(ioe.getMessage());
        } catch (MediaException me) {
         form.append(me.getMessage());
        }
    }
   
    class Video extends Thread {
        VideoControlExample midlet;
        public Video(VideoControlExample midlet) {
            this.midlet = midlet;
        }
       
        public void run() {
            captureVideo();           
        }
       
        public void captureVideo() {
            try {
             //byte[] photo = videoControl.getSnapshot("encoding=jpeg");
             //form.append("FM: 3 " + Runtime.getRuntime().freeMemory()/1000);
             form.append("before getSnapshot");
                byte[] photo = videoControl.getSnapshot("encoding=jpeg&width=640&height=480");
                form.append("after getSnapshot");
                if (photo == null)
                 form.append("byte[] returned by getsnapshot = null");
                else
                 form.append("byte[] returned by getsnapshot not null");
             //byte[] photo = videoControl.getSnapshot("encoding=jpeg&width=640&height=480");
                //form.append("FM: AA ");
                Image image = Image.createImage(photo, 0, photo.length);
               // form.append("FM: BB ");
                form.append(image);
                display.setCurrent(form);               
                player.close();
                player = null;
                videoControl = null;
                form.append("FM: 4 " + Runtime.getRuntime().freeMemory()/1000);
                photo = null;
                image = null;
                System.gc();
                form.append("FM: 5 " + Runtime.getRuntime().freeMemory()/1000);
            } catch (OutOfMemoryError me) {
                 form.append("OutOfMemoryError");
                 player.close();
                    player = null;
                    videoControl = null;
            } catch (MediaException me) {
             form.append("MediaException " + me.toString());
             player.close();
                player = null;
                videoControl = null;
            }
            catch (Throwable me) {
             form.append("Throwable " + me.toString());
             player.close();
                player = null;
                videoControl = null;
            }
        }
    }
}

class VideoCanvas extends Canvas {
    private VideoControlExample midlet;
   
    public VideoCanvas(VideoControlExample midlet, VideoControl videoControl) {
        int width = getWidth();
        int height = getHeight();
        this.midlet = midlet;
       
        videoControl.initDisplayMode(VideoControl.USE_DIRECT_VIDEO, this);
        /*try {
            videoControl.setDisplayLocation(2, 2);
            //videoControl.setDisplaySize(176, 144);
            videoControl.setDisplaySize(180, 160);
            //videoControl.setDisplayFullScreen(true);
        } catch (MediaException me) {
         me.printStackTrace();
        }*/
        videoControl.setVisible(true);
    }
   
    public void paint(Graphics g) {
        int width = getWidth();
        int height = getHeight();
       
        g.setColor(255, 0, 0);
        g.drawRect(0, 0, width - 1, height - 1);
        g.drawRect(1, 1, width - 3, height - 3);
    }
}

Kudos!
11-05-2009 05:22 AM
 
Jump to Page:   1