我在VisualBasic .net中有一个WebService,它使用以下代码给出一张图片:
<WebMethod()> _
Public Function DevuleveImagen() As Byte()
Dim imagen As Byte()
Dim bm As New Bitmap("C:\Imagen.jpg")
Dim ms As New IO.MemoryStream
bm.Save(ms, Imaging.ImageFormat.Jpeg)
imagen = ms.GetBuffer()
ms.Close()
ms = Nothing
Return imagen
End Function
我尝试从Android中重温这张照片:
private void PonLogo(){
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME1);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
envelope.dotNet = true;
try {
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION1, envelope);
SoapObject result = (SoapObject)envelope.bodyIn;
if(result != null)
{
Object o = result.getProperty(0);
byte[] b = o.toString().getBytes();
Bitmap bMap = BitmapFactory.decodeByteArray(b, 0, b.length);
imgbannerjuego.setImageBitmap(bMap);
}
else
{
Toast.makeText(getApplicationContext(), "No Response",Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
e.printStackTrace();
}
}
并且调试一切似乎没问题,但是当应用程序启动时,我应该看到图片的地方是白色的。我认为这可能是转换问题,但我不知道如何解决它。
有人能帮助我吗?
答案 0 :(得分:0)
你能放一些logcat日志吗?我想有一个例外,因为您在UI线程中处理网络事件。试试这样。
private void PonLogo(){
final SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME1);
final SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
envelope.dotNet = true;
new Thread(new Runnable() {
public void run() {
try {
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION1, envelope);
SoapObject result = (SoapObject)envelope.bodyIn;
if(result != null) {
Object o = result.getProperty(0);
byte[] b = o.toString().getBytes();
Bitmap bMap = BitmapFactory.decodeByteArray(b, 0, b.length);
yourActivity.runOnThreadUi(new Runnable() {
public void run() {
imgbannerjuego.setImageBitmap(bMap);
});
}
} else {
yourActivity.runOnThreadUi(new Runnable() {
public void run() {
Toast.makeText(getApplicationContext(), "No Response",Toast.LENGTH_LONG).show();
});
}
} catch (Exception e) {
e.printStackTrace();
}
}).start();
}