Tuesday, April 24, 2007

how to send image from mobile phone to servlet :Mobile Side

public synchronized void run(){
HttpConnection c = null;
OutputStream os = null;
try{
c = (HttpConnection)Connector.open(url);
// Set the request method and headers
c.setRequestMethod(HttpConnection.POST);
c.setRequestProperty("User-Agent",
"Profile/MIDP-2.0 Configuration/CLDC-1.0");
c.setRequestProperty("Content-Language", "en-US");
os = c.openOutputStream();
Image myimage = Image.createImage(imageData,0,imageData.length);
int w = myimage.getWidth();
int h = myimage.getHeight();
DataOutputStream out = new DataOutputStream(os);
System.out.println("width:"+myimage.getWidth());
System.out.println("height:"+myimage.getHeight());
int [] rgbdata = new int[160*120];
System.out.println("length :"+rgbdata.length);
myimage.getRGB(rgbdata, 0, myimage.getWidth(), 0, 0, myimage.getWidth(), myimage.getHeight());

for(int i = 0 ;i LT h;i++){
for(int j=0;j LT w;j++){
out.writeUTF(rgbdata[i*w+j]+"?");
}
}
}
catch(Exception e){
}
}

No comments: