i have to retrieve image of all size from server to android mobile with reference to id ,so that i tried with this below coding and successfully got the base 64 string and retrieved image for equivalent base64string it works fine for small size images but when i go for big size image it remains black screen not able to get large size images on screen through this method.
thanks in advance.
how to retrieve
large size base64 string through soap object from a server
package com.imageload;
import java.io.IOException;
import java.util.StringTokenizer;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Typeface;
import android.os.Bundle;
import android.util.Base64;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
public class ImageloadActivity extends Activity {
/** Called when the activity is first created. */
private Button submit,clr,ext;
private ImageView imageView;
private TextView institute,orderno,name,mobno,handeled,regdat,delvdat,pname,pamt,dirby,regby,delby;
String val11,val12,val13,val14;
String str = null,str2 = null;
String error="0",IiD;
/* private static final String SOAP_ACTION = "http://tempuri.org/sta1";
private static final String METHOD_NAME = "sta1";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://cyberstudents.in/newand//service.asmx";*/
private static final String SOAP_ACTION = "http://tempuri.org/IMAGE";
private static final String METHOD_NAME = "IMAGE";
private static final String NAMESPACE = "http://tempuri.org/";
//private static final String URL = "http://cyberstudents.in/crdroid//service.asmx";
private static final String URL = "http:///localdb/Service.asmx";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
this.orderno=(TextView)this.findViewById(R.id.ordernoeditText);
this.pname=(TextView)this.findViewById(R.id.insTextView);
this.submit=(Button)this.findViewById(R.id.getbutton);
this.clr=(Button)this.findViewById(R.id.clearbutton);
this.ext=(Button)this.findViewById(R.id.Exitbutton);
this.imageView =(ImageView) findViewById(R.id.imageView1);
orderno.setText("CB2-1112-CEA0883");
this.submit.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
IiD=orderno.getText().toString();
if(error.equals("0"))
{
SoapObject request = new SoapObject(NAMESPACE,METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
request.addProperty("ID",IiD);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try
{
try
{
androidHttpTransport.call(SOAP_ACTION, envelope);
}
catch (XmlPullParserException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
SoapPrimitive result = (SoapPrimitive)envelope.getResponse();
//to get the data should be a base
String resultData = result.toString();
//pname.setText(resultData);
byte[] decodedString = Base64.decode(resultData, Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
imageView.setImageBitmap(decodedByte);
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
});
this.clr.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
pname.setText("");
}
});
this.ext.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
System.exit(0);
}
});
}
}
It returns null for soapprimitive(result) when it returns image size bigger than 150kb or 2500*3000 dimention
[WebMethod]
public string IMAGE(string ID)
{
SqlConnection conn = new SqlConnection("Data Source=;Initial Catalog=;Persist Security Info=True;User ID=sa;");
conn.Open();
SqlDataAdapter sdImageSource = new SqlDataAdapter();
sdImageSource.SelectCommand = new SqlCommand("select ImageData from ImagesStore where ImageId=('" + ID + "')", conn);
DataSet dsImage = new DataSet();
sdImageSource.Fill(dsImage);
byte[] blob = (byte[])dsImage.Tables[0].Rows[0][0];
int k = blob.Length;
string c = Convert.ToBase64String(blob);
return c;
}