You Are Here:

Community: Developer Discussion Boards

#1 Old Can not turn camera on, Nokia 6070 - 2009-04-18, 04:41

Join Date: Apr 2009
Posts: 6
ammanage
Offline
Registered User
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.
Reply With Quote

#2 Old Thumbs up Re: Can not turn camera on, Nokia 6070 - 2009-04-18, 06:23

Join Date: Sep 2008
Posts: 1,195
Location: DELHI
Send a message via Yahoo to jitu_goldie
jitu_goldie's Avatar
jitu_goldie
Offline
Forum Nokia Champion
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..
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules

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

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
Nokia Mobile VPN Client marcyl Symbian Networking & Messaging 1 2003-12-01 15:47

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomE2fforumE2fshowthreadE2ephpE3ftE3d18645X qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE44iscussionQ qdcZtypeQUqfntypeZE44iscussionContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZentertainmentQ qfnZtopicQUqfnTopicZj2meQ qfnZtopicQUqfnTopicZjavaQ qfnZtopicQUqfnTopicZmediaQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE44iscussionQ qfnZtypeQUqfntypeZE44iscussionContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE44iscussionQ qrdfZtypeQUqfntypeZE44iscussionContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ