Results 1 to 3 of 3
Thread: Visualizing an image on Canvas
- 07-31-2008, 03:36 PM #1
Member
- Join Date
- Jul 2008
- Posts
- 5
- Rep Power
- 0
Visualizing an image on Canvas
I have to establish a http connection with "google.maps" and after that download a map with a specified coordinates, zoom and size.Then I convert it into an immage and visualize it on a Canvas. I have wrote down the following code, and it seems to connect to "google.maps" but on the display there is nothing. I have made 2 classes , I don't know whether this is correct. There are two methods that I do not use as well but it doesn't matter. So please help me.
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.io.*;
import java.io.*;
/**
*
*/
public class MidletMappa extends MIDlet implements Runnable{
byte[] imageData=null;
static Image mappa;
static int zoom=10;
static double lat=43.1;
static double lon=12.0;
static String size="512x512";
static String url="I CANNOT USE LINKS IN THIS FORUM/staticmap?center="+lat+","+lon+"&zoom="+zoom+"&siz e="+size+"&key=ABQIAAAAdtc9p-tYjhOn-cBjT4ZqOhQFw05-dUaae2f4nTjx_OHejRkIjhTD-H8rX2tIVL6gWFMwoXqZwpfMAA";
private Display mdisplay;
public void startApp() throws MIDletStateChangeException {
System.out.println(">>Start midlet");
mdisplay=Display.getDisplay(this);
Thread t=new Thread(this);
t.start();
CanvasMappa.setImage(mappa);
mdisplay.setCurrent(new CanvasMappa());
}//end start
public void pauseApp() {
System.out.println("Pause midlet");
}//end pause
public void destroyApp(boolean unconditional) {
System.out.println("Destroy midlet");
notifyDestroyed();
}//end destroy
public void run(){
DataInputStream in=null;
HttpConnection connection=null;
try{
connection=(HttpConnection)Connector.open(url);//creo una connessione http
//connection.setRequestMethod(HttpConnection.GET);
if(connection.getResponseCode()==HttpConnection.HT TP_OK){// connessione ok
int length=(int)connection.getLength();
if (length!=-1){
imageData=new byte[length];
in=new DataInputStream(connection.openDataInputStream());
in.readFully(imageData);
}
else{
int chunkSize=512;
int index=0;
int readLength=0;
in=new DataInputStream(connection.openInputStream());
imageData=new byte[chunkSize];
do{
if(imageData.length<index+chunkSize){
byte[] newData=new byte[index+chunkSize];
System.arraycopy(imageData, 0, newData, 0, imageData.length);
imageData=newData;
}//end if
readLength=in.read(imageData,index,chunkSize);
index+=readLength;
}while(readLength==chunkSize); //end do-while
length=index;
}
mappa=Image.createImage(imageData, 0, length);//eventualmente si puo' usare un altro metodi create image
}//end connessione ok
else{//connessione no ok
Alert a=new Alert("Connessione non riuscita");
a.setTimeout(3000);
mdisplay.setCurrent(a);
}//end connessione no OK
}//end try
catch(Exception e){
e.printStackTrace();
Alert a=new Alert(e.getMessage());
mdisplay.setCurrent(a);
}//end catch
}//end run
public static void setParameters(int zo, double lattitudine, double longitudine, String si, String indirizzo ){
zoom=zo;
lat=lattitudine;
lon=longitudine;
size=si;
url=indirizzo;
}//end setParameters
}//end class
public class CanvasMappa extends Canvas {
static Image mappa;
static int zoom=10;
static double lat=43.1;
static double lon=12.0;
static String size="512x512";
static String url=I CANNOT USE THE LINK IN THIS FORUM staticmap?center="+lat+","+lon+"&zoom="+zoom+"&siz e="+size+"&key=ABQIAAAAdtc9p-tYjhOn-cBjT4ZqOhQFw05-dUaae2f4nTjx_OHejRkIjhTD-H8rX2tIVL6gWFMwoXqZwpfMAA";
public static void setImage(Image im){
mappa=im;
}//end setImage
protected void paint(Graphics g) {
g.drawImage(mappa, getWidth(), getHeight(), Graphics.HCENTER|Graphics.VCENTER);
}//end paint
public static void setParameters(int zo, double lattitudine, double longitudine, String si, String indirizzo ){
zoom=zo;
lat=lattitudine;
lon=longitudine;
size=si;
url=indirizzo;
}//end setParameters
}//end class
- 07-31-2008, 04:45 PM #2
What does google.maps return?t seems to connect to "google.maps"
I don't see a main() method to execute the above. How is it started?
- 08-01-2008, 10:25 AM #3
Member
- Join Date
- Jul 2008
- Posts
- 5
- Rep Power
- 0
Similar Threads
-
Using a Canvas
By a_klasanov in forum CLDC and MIDPReplies: 3Last Post: 12-08-2008, 10:36 AM -
Canvas Example
By Java Tip in forum SWTReplies: 0Last Post: 07-25-2008, 02:22 PM -
Converting multiple banded image into single banded image... Image enhancement
By archanajathan in forum Advanced JavaReplies: 0Last Post: 01-08-2008, 05:29 PM -
Using SWT Canvas
By Java Tip in forum Java TipReplies: 0Last Post: 01-08-2008, 09:06 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks