1 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. 2 //Coding Section3String string =base64.encodetostring (Str.getbytes (), base64.default);4 //decoding part of string is the information sent from the service side.5 byte[] byteicon=Base64.decode (string,base64.default);6 for(inti = 0; i < byteicon.length; ++i) {7 if(Byteicon[i] < 0) { 8Byteicon[i] + = 256; 9 }} Ten //Create a File object OneFile IconFile =NewFile ("Usericon.png"); AFileOutputStream fos =NewFileOutputStream (iconfile); - if(!iconfile.exists ()) - { the Iconfile.creatnewfile (); - } - //write picture data into a file to form a picture - Fos.write (Byteicon); + - I searched the internet, found that my writing has become complicated, in fact, Byteicon can be converted directly to bitmap, but this will not be able to achieve the local save + //Service Side A //encode, remember this stream, often used to switch pictures and Base64 data atBytearrayoutputstream BAOs =NewBytearrayoutputstream (); - //picture is compressed and converted into a stream, bitmap I don't initialize it here. -Bitmap.compress (bitmap.compressformat,100, BAOs); - byte[] Byteserver =Baos.tobytearray (); -String result =base64.encodetostring (ByteServer.Base64.DEFAULT); -[Enter a link description here] [1] in - //Android Side to byte[] Byteicon =Base64.decode (result,base64.default); +Bitmap Bitmap = Bitmapfactory.decode (byteicon,0,byteicon.length);
The above data is transferred from: http://my.oschina.net/lengwei/blog/355901 only as a collection,
In my own article is also used in the Base64, interested can go to see, http://www.cnblogs.com/fuck1/p/5459660.html
Simple use of Base64 in Android