Unable to reconstruct bitmap from ksop2 response

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

Unable to reconstruct bitmap from ksop2 response

Postby sooraj.rit » Tue Jan 13, 2009 12:35 pm

Hi , I am trying to download a bitmap from a web service ( created in .Net ). My web service consists of a method "GetImage" , and the server machine is returning the image stored in it as String which is converted to Byte[].but when i try to reconstruct a bitmap from the so obtained byte, it seems to be null.I have attached the source code. any sort of help is greatly appreciated.



public class HelloWeb extends Activity {

private static final String SOAP_ACTION = "http://webservice.org/ GetImage";
private static final String METHOD_NAME = "GetImage";
private static final String NAMESPACE = "http://webservice.org/";
private static final String URL = "http://10.1.26.21/Webservice/ Service1.asmx";
private Object resultRequestSOAP = null;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//TextView tv = new TextView(this);
ImageView tv = new ImageView(this);
setContentView(tv);

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope (SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject( request );
HttpTransportSE transport = new HttpTransportSE(URL);
try
{
transport.call(SOAP_ACTION, envelope);
resultRequestSOAP = envelope.getResponse();

String results = resultRequestSOAP.toString();
byte[] bresult = results.getBytes(); //
everything is fine upto this point

Bitmap bitmap ;
bitmap = BitmapFactory.decodeByteArray(bresult , 0,
bresult.length); //here I get a null
bitmap

ImageView img = (ImageView) findViewById (R.id.ImageView01);
img.setImageBitmap(bitmap);

}
catch (Exception aE)
{
aE.printStackTrace ();
}
}
}
sooraj.rit
Freshman
Freshman
 
Posts: 5
Joined: Tue Jan 13, 2009 12:29 pm
Location: Trivandrum,India

Top

Postby EveningNewbs » Sun Jul 12, 2009 5:40 am

I just solved this same issue today. The problem is that String.getBytes() uses the default encoding (I think it's UTF-8) to decode the string, which ends up changing some of the binary data. I ended up having to do this:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. byte[] bresults=new byte[results.length()];
  2.  
  3. for(long i=0; i<results.length(); i++)
  4.  
  5.         bresults[i]=results.charAt(i);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4

There's probably a way to do that that's more optimized, but I didn't feel like searching for it after spending half of the day making it work.
EveningNewbs
Junior Developer
Junior Developer
 
Posts: 14
Joined: Mon Nov 17, 2008 4:27 pm

Postby desuvinodkumar » Mon Jul 13, 2009 8:51 am

HI


String results = resultRequestSOAP.toString();

What is the Response u were getting here....

can u paste it ....

same problem i am facing ....
Vinod...
User avatar
desuvinodkumar
Senior Developer
Senior Developer
 
Posts: 102
Joined: Mon Mar 23, 2009 6:51 am
Location: India

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 3 guests