1

我在 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();
    }
}

而且调试一切似乎没问题,但是当应用程序启动时,我应该看到图片的地方是白色的。我认为这可能是一个转换问题,但我不知道如何解决它。

有人可以帮助我吗?

4

1 回答 1

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();
    }
于 2013-04-28T00:55:00.663 回答