Service-side picture information is converted to a string, to the Android client, the Android side need to decode this information into a picture and saved locally. Encode part of String string = Base64.encodetostring (Str.getbytes (), base64.default); Decoding part of string is the information sent by the server byte[] byteicon= base64.decode (String,base64.default); for (int i = 0; i < byteicon.length; ++i) { if (Byteicon[i] < 0) {Byteicon[i] + = 256; }}//Create a File Object iconfile = "New File" ("Usericon.png"); FileOutputStream fos = new FileOutputStream (iconfile); if (!iconfile.exists ()) {iconfile.creatnewfile (); }//the picture data into a file to form a picture fos.write (Byteicon); I went to the internet to search, found that my writing has become more complex, in fact, Byteicon can be directly converted to bitmap, but this will not be able to achieve the local save//server//code, Remember this stream, often used for images and Base64 data switching bytearrayoutputstream BAOs = new Bytearrayoutputstream ();//Picture is compressed and converted into a stream, Bitmap Here I do not initialize the bitmap.compress (Bitmap.compressformat,100,baos); byte[] Byteserver = Baos.tobytearray (); String result = base64.encodetostring (ByteServer.Base64.DEFAULT); [Enter a link description here] [1]//android end byte[] Byteicon = Base64.decode (Result,base64.default); Bitmap Bitmap = Bitmapfactory.decode (byteicon,0,byteicon.length);
Android Base64 encoding decoding