2011-08-31 3 views
1

Je suis en train de récupérer une image de ma table SQLite et la convertir en un tableau d'octets en utilisant ce code:l'image android à .net webservice

byte[] imageByteArray = cImage.getBlob(cImage.getColumnIndex("ImageData")); 

qui fonctionne très bien (je l'ai prouvé en décodant revenir à la image originale comme ceci:

ByteArrayInputStream imageStream = new ByteArrayInputStream(imageByteArray); 
Bitmap theImage = BitmapFactory.decodeStream(imageStream); 

le problème que j'ai est que je dois serialise les données d'image et l'envoyer via des services Web .NET, puis le décoder à l'autre extrémité

J'utilise cela. code pour encoder l'octet [] en une chaîne Base64:

String sImageData = Base64.encode(imageByteArray); 

Puis l'ajouter en tant que propriété à mon appel de service.

L'appel prend un certain temps pour terminer ce qui indique qu'il envoie les données - même si je reçois l'exception « La valeur ne peut être nulle » quand je le fais dans le service Web:

byte[] baImageData = Convert.FromBase64String(sImageData); 

Je ne suis pas Bien sûr, comment je peux déboguer plus loin - est-ce que je manque quelque chose d'évident?

Répondre

0

cela fonctionne très bien, mais si vous envoyez une longue image, il se bloque.

dans Android:

private static final String NAMESPACE = "http://tempuri.org/"; 
private static String URL="http://XXX.XX.113.79/Sincro_Mobile/Sincro.asmx"; 
ws_btn_Enviar_foto.setOnClickListener(new View.OnClickListener() { 

      public void onClick(View v) { 

       final String METHOD_NAME = "FOTO_and"; 
       final String SOAP_ACTION ="http://tempuri.org/FOTO_and"; 

       ws_resultado.setText(""); 
       request = new SoapObject(NAMESPACE, METHOD_NAME); 
       Bitmap imagen_decodificar = BitmapFactory.decodeFile (Environment.getExternalStorageDirectory().getAbsolutePath()+ 
         "/"+Globales.fotos_sgi+"/tomafoto1_resize_70.jpg"); 
       ByteArrayOutputStream out = new ByteArrayOutputStream();  
       imagen_decodificar.compress(CompressFormat.JPEG, 70, out);  
       byte[] imagebyte = out.toByteArray(); 
       String strBase64 = Base64.encodeBytes(imagebyte); 
       request.addProperty("user", "ap"); 
       request.addProperty("pass", "qwerty"); 
       request.addProperty("x", contrasena); 
       request.addProperty("buffer",strBase64); 
       request.addProperty("filename","primer_foto.jpg"); 
       //request.addProperty("Fecha_MOVIMIENTOS_y_FOTOS",dia_de_hoy.toString()); 
       envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
       envelope.dotNet = true; //se asigna true para el caso de que el WS sea de dotNet 
       envelope.setOutputSoapObject(request); 
       HttpTransportSE transporte = new HttpTransportSE(URL); 

       try { 
        transporte.call(SOAP_ACTION, envelope); 
        resultsRequestSOAP = (SoapPrimitive)envelope.getResponse(); 
        ws_resultado.setText(resultsRequestSOAP.toString()) ; 
        } 
       catch (IOException e) { 
        ws_resultado.setText(e.toString());; 
        } 
       catch (XmlPullParserException e) { 
        ws_resultado.setText(e.toString());; 
        } 

       } 
     }); 

Dans .net Webservice:

<WebMethod()> Public Function FOTO_and(ByVal user As String, ByVal pass As String, _ 
    ByVal x As String, ByVal buffer As Byte(), ByVal filename As String) As String 

     Dim Log As String = Validacion_User_EMEI(user, pass, x) 

     If Log <> Estados_Sincro.OK Then 
      Return Log 
     End If 

     '--VERIFICA QUE EXISTA LA CARPETA PARA ALMACENAR LA FOTO 

     Dim Path_Fotos As String 

     Path_Fotos = AppSettings.GetValues("Fotos")(0) + Now.ToString("yyMMdd") 
     If Directory.Exists(Path_Fotos) = False Then 
      Directory.CreateDirectory(Path_Fotos) 
     End If 

     '---VERIFICA QUE LA FOTO NO EXISTA 

     If File.Exists(Path_Fotos + "\" + filename) Then 
      Kill(Path_Fotos + "\" + filename) 
     End If 

     '--GUARDA LA FOTO 

     Dim binWriter As New BinaryWriter(File.Open(Path_Fotos + "\" + filename, _ 
     FileMode.CreateNew, FileAccess.ReadWrite)) 
     binWriter.Write(buffer) 
     binWriter.Close() 

     Return Estados_Sincro.OK 

    End Function 
0

La partie android me semble bien.