| Reply | « Previous Thread | Next Thread » |
|
Hi everyone
I am very new with J2ME. Actually, I have tried to turn camera on with MMAPI. I use NetBeans for IDE and my program work well with mobile emulator. Unfortunately, when I install this program to my cell phone, Nokia 6070, there ‘s nothing happened. Only message “Running in background and camera isn’t turned on. However , I have check if my phone supporting MMAPI. It supports MMAPI. http://www.forum.nokia.com/devices/6070 This is code of my program. There ‘re three files. 1. Capture.java : MIDlet import javax.microedition.midlet.*; import javax.microedition.lcdui.*; import javax.microedition.media.*; import javax.microedition.media.control.*; //import com.sun.midp.io.Base64; import java.lang.Object.*; /** * @author Theeranit */ public class Capture extends MIDlet { private Player player; private Camera camera; private VideoControl videoControl; private int cameraWidth; public Capture() { } public void startApp() { Thread th = new Thread() { public void run() { showCamera(); } }; th.start(); } public void pauseApp() { byte[] amm = "abc".getBytes(); //String stringEncode = Base64.encode(amm, 0, amm.length); } public void destroyApp(boolean unconditional) { } public void showCamera() { try { player = Manager.createPlayer("capture://video"); player.realize(); player.prefetch(); videoControl = (VideoControl) player.getControl("VideoControl"); camera = new Camera(this, videoControl); cameraWidth = camera.getWidth(); Display.getDisplay(this).setCurrent(camera); player.start(); } catch (Exception e) { } } public void capturePhoto() { try { byte[] raw = videoControl.getSnapshot(null); //player.stop(); Image image = Image.createImage(raw, 0, raw.length); Photo photo = new Photo(image); Display.getDisplay(this).setCurrent(photo); } catch (MediaException e) { System.out.println(e.getMessage()); } } /* private Image createThumbnail(Image image) { int sourceWidth = image.getWidth(); int sourceHeight = image.getHeight(); int thumbWidth = camera.getWidth(); int thumbHeight = -1; if (thumbHeight == -1) { thumbHeight = thumbWidth * sourceHeight / sourceWidth; } Image thumb = Image.createImage(thumbWidth, thumbHeight); Graphics g = thumb.getGraphics(); for (int y = 0; y < thumbHeight; y++) { for (int x = 0; x < thumbWidth; x++) { g.setClip(x, y, 1, 1); int dx = x * sourceWidth / thumbWidth; int dy = y * sourceHeight / thumbHeight; g.drawImage(image, x - dx, y - dy, Graphics.LEFT | Graphics.TOP); } } Image immutableThumb = Image.createImage(thumb); return immutableThumb; } */ } 2. Camera.java : Canvas import javax.microedition.lcdui.*; import javax.microedition.media.*; import javax.microedition.media.control.*; /** * @author Theeranit */ public class Camera extends Canvas implements CommandListener { /** * constructor */ private Command exitCommand, captureCommand; private Capture capture; public Camera(Capture midlet, VideoControl videoControl) { exitCommand = new Command("Exit",Command.EXIT,0); captureCommand = new Command("Capture", Command.SCREEN,1); this.addCommand(exitCommand); this.addCommand(captureCommand); this.setCommandListener(this); capture = midlet; videoControl.initDisplayMode(VideoControl.USE_DIRECT_VIDEO, this); try { //videoControl.setDisplayLocation(2, 2); videoControl.setDisplaySize(getWidth(), getHeight()); } catch (MediaException me) { try { videoControl.setDisplayFullScreen(true); } catch (MediaException me2) { } } videoControl.setVisible(true); } /** * paint */ public void paint(Graphics g) { g.setColor(0, 0, 0); g.drawRect(0, 0, getWidth(), getHeight()); } /** * Called when action should be handled */ public void commandAction(Command c, Displayable s) { if(c == exitCommand){ capture.notifyDestroyed(); } else if(c == captureCommand){ Thread th = new Thread () { public void run() { capture.capturePhoto(); } }; th.start(); } } /** * Called when a key is pressed. */ protected void keyPressed(int keyCode) { } /** * Called when a key is released. */ protected void keyReleased(int keyCode) { } /** * Called when a key is repeated (held down). */ protected void keyRepeated(int keyCode) { } /** * Called when the pointer is dragged. */ protected void pointerDragged(int x, int y) { } /** * Called when the pointer is pressed. */ protected void pointerPressed(int x, int y) { } /** * Called when the pointer is released. */ protected void pointerReleased(int x, int y) { } } 3. Photo.java : Canvas import javax.microedition.lcdui.*; import javax.microedition.media.*; import javax.microedition.media.control.*; /** * @author Theeranit */ public class Photo extends Canvas implements CommandListener { /** * constructor */ Image image; public Photo(Image img) { image = img; } /** * paint */ public void paint(Graphics g) { g.setColor(255, 255, 255); g.fillRect(0, 0, getWidth(), getHeight()); g.drawImage(createThumbnail(image), 0, 0, Graphics.TOP | Graphics.LEFT); } private Image createThumbnail(Image image) { int sourceWidth = image.getWidth(); int sourceHeight = image.getHeight(); int thumbWidth = getWidth(); //int thumbWidth = 128; int thumbHeight = -1; if (thumbHeight == -1) { thumbHeight = thumbWidth * sourceHeight / sourceWidth; } Image thumb = Image.createImage(thumbWidth, thumbHeight); Graphics g = thumb.getGraphics(); for (int y = 0; y < thumbHeight; y++) { for (int x = 0; x < thumbWidth; x++) { g.setClip(x, y, 1, 1); int dx = x * sourceWidth / thumbWidth; int dy = y * sourceHeight / thumbHeight; g.drawImage(image, x - dx, y - dy, Graphics.LEFT | Graphics.TOP); } } Image immutableThumb = Image.createImage(thumb); return immutableThumb; } /** * Called when a key is pressed. */ protected void keyPressed(int keyCode) { } /** * Called when a key is released. */ protected void keyReleased(int keyCode) { } /** * Called when a key is repeated (held down). */ protected void keyRepeated(int keyCode) { } /** * Called when the pointer is dragged. */ protected void pointerDragged(int x, int y) { } /** * Called when the pointer is pressed. */ protected void pointerPressed(int x, int y) { } /** * Called when the pointer is released. */ protected void pointerReleased(int x, int y) { } /** * Called when action should be handled */ public void commandAction(Command command, Displayable displayable) { } } I’ m looking forward to receive good advice. Thank you. |
|
code works perfectly on sony ericsson k790i and sony ericsson 810i.
Please check the settings of multimedia in suite settings of application in app manager of device. thanks, jitu_goldie.. KEEP TRYING.. |
| jitu_goldie |
| View Public Profile |
| Find all posts by jitu_goldie |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| Thread | Thread Starter | Forum | Replies | Last Post |
|---|---|---|---|---|
| Nokia Mobile VPN Client | marcyl | Symbian Networking & Messaging | 1 | 2003-12-01 15:47 |