[J2ME] Afficher une image web
alec.po
Messages postés
134
Statut
Membre
-
alec.po Messages postés 134 Statut Membre -
alec.po Messages postés 134 Statut Membre -
Bonjour,
Je programme une petite application J2ME, et j'ai besoin d'afficher une image web dans un canvas.
J'arrive a afficher une image local grâce à :
Donc pour une image distante j'utilise :
Avec cette méthode :
Et sa plante....
Je débute en J2ME alors je comprend rien.
Si quelqu'un peut m'aider svp.
Merci
Je programme une petite application J2ME, et j'ai besoin d'afficher une image web dans un canvas.
J'arrive a afficher une image local grâce à :
g.drawImage(Image.createImage("image.png"), 0, 0, Graphics.VCENTER | Graphics.HCENTER);
Donc pour une image distante j'utilise :
InputStream is = null; ...... g.drawImage(Image.createImage(is), 0, 0, Graphics.VCENTER | Graphics.HCENTER); ......
Avec cette méthode :
public void dwlImage() throws Exception
{
System.out.println("chargement.....");
new Thread(new Runnable(){
public void run()
{
String url = "http://site/fichier.png";
HttpConnection c = null;
int rc;
try {
c = (HttpConnection)Connector.open(url);
// Getting the response code will open the connection,
// send the request, and read the HTTP response headers.
// The headers are stored until requested.
rc = c.getResponseCode();
if (rc != HttpConnection.HTTP_OK) {
throw new IOException("HTTP response code: " + rc);
}
is = c.openInputStream();
// Get the ContentType
String type = c.getType();
// Get the length and process the data
int len = (int)c.getLength();
if (len > 0) {
int actual = 0;
int bytesread = 0 ;
byte[] data = new byte[len];
while ((bytesread != len) && (actual != -1)) {
actual = is.read(data, bytesread, len - bytesread);
bytesread += actual;
}
} else {
int ch;
while ((ch = is.read()) != -1) {
}
}
} catch (ClassCastException e) {
throw new IllegalArgumentException("Not an HTTP URL");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (c != null)
try {
c.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}).start();
}
Et sa plante....
Je débute en J2ME alors je comprend rien.
Si quelqu'un peut m'aider svp.
Merci
A voir également:
- [J2ME] Afficher une image web
- Web office - Guide
- Légender une image - Guide
- Création site web - Guide
- Image iso - Guide
- C'est quoi une adresse web - Guide