|
|
|
|
|
MOTODEV Discussion Boards :
Java ME :
Multimedia and Graphics :
Take a picture on W7
|
|
|
|
|
|
|
|
|

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

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
|
|
|
|
11-04-2009 06:06 PM
|
|
|
|
|
|

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

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); } }
|
|
|
|
11-05-2009 05:22 AM
|
|
|
|
|
|
|
|
|
|
Use this field to search for information ONLY within the discussion boards.
Use the search field in the upper right hand corner to search the entire MOTODEV web site.