Simple use of Base64 in Android

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.