You Are Here:

Community: Developer Discussion Boards

#1 Old Displaying image - 2004-11-03, 13:31

Join Date: Mar 2003
Posts: 26
kapot
Offline
Registered User
I tried to "continuosly" grab and display a jpg image from http address. But my code below does not work :(

Anyone know how to fix this ?

Thanks

package jpgmidlet;

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.util.Vector;
import java.io.IOException;
import java.io.DataInputStream;
import javax.microedition.io.HttpConnection;
import javax.microedition.io.ContentConnection;
import javax.microedition.io.Connector;

public class JpgMidlet extends MIDlet implements Runnable
{
private Display display;
private Thread thread;
private Frame frame;

public JpgMidlet() {
display = Display.getDisplay(this);

frame = new Frame();
}

protected void startApp() {
run();
}

protected void pauseApp() {
}

protected void destroyApp(boolean unconditional) {
}

private Image createImage(String name) throws IOException {

// Load from a ContentConnection
HttpConnection c = null;
DataInputStream is = null;

try {
c = (HttpConnection)Connector.open(name);
int status = c.getResponseCode();

if (status != 200) {
throw new IOException("HTTP Response Code = " + status);
}

int len = (int)c.getLength();
String type = c.getType();

if (len > 0) {
is = c.openDataInputStream();
byte[] data = new byte[len];
is.readFully(data);
return Image.createImage(data, 0, len);
} else {
throw new IOException("Content length is missing");
}

} finally {
if (is != null)
is.close();

if (c != null)
c.close();
}

}


public void run() {
Image theimage = null;

String name = "http://127.0.0.1:11001/image.jpg";
try {
theimage = Image.createImage(name);
} catch (IOException err) {
}

frame.setImages(theimage);
display.setCurrent(frame);

}
}

class Frame extends Canvas {

private Image image;

Frame() {
image = Image.createImage(getWidth(), getHeight());
}

void setImages(Image theimage) {
Image image = theimage;
}

protected void paint(Graphics g) {
g.drawImage(image, 0, 0, Graphics.LEFT|Graphics.TOP);
}

}
Reply With Quote

#2 Old 2004-11-06, 15:55

Join Date: Jun 2003
Posts: 4,325
Location: Cheshire, UK
grahamhughes's Avatar
grahamhughes
Online
Forum Nokia Champion
You're passing the URL to Image.createImage(), which won't accept a URL as a parameter. You don't call your own createImage() method anywhere.

Graham.
Reply With Quote

#3 Old Displaying image - 2004-11-16, 08:15

Join Date: Nov 2004
Posts: 1
shipf1ferrari
Offline
Registered User
Then, how do u solve this ? Cud u help ?

Regards,
Shilpa.
Reply With Quote

#4 Old 2004-11-16, 11:10

Join Date: Jun 2003
Posts: 4,325
Location: Cheshire, UK
grahamhughes's Avatar
grahamhughes
Online
Forum Nokia Champion
The trick is, not to name your methods so that they have the same name as a different method in a different class that works a different way.

Change the name of the createImage() method in this code to fetchImage(), and make sure the method actually gets called from somewhere.

Graham.
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

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