Connect with
 
In Android, I am facing many time convert Bitmap to String and String to Bitmap. When send or receive Bitmap to server and storing Image in database.

Bitmap to String:
public String BitMapToString(Bitmap bitmap){
            ByteArrayOutputStream baos=new  ByteArrayOutputStream();
            bitmap.compress(Bitmap.CompressFormat.PNG,100, baos);
            byte [] arr=baos.toByteArray();
            String result=Base64.encodeToString(arr, Base64.DEFAULT);
            return result;
      }


String to Bitmap:
public Bitmap StringToBitMap(String image){
       try{
           byte [] encodeByte=Base64.decode(image,Base64.DEFAULT);
           Bitmap bitmap=BitmapFactory.decodeByteArray(encodeByte, 0, encodeByte.length);
           return bitmap;
         }catch(Exception e){
           e.getMessage();
          return null;
         }
 }
Padma Reddy
11/22/2012 01:38:12 pm

thank u for ur post , i got solution for my problem,

Reply
6/12/2013 09:28:04 pm

good for begginners

Reply
fgfgfgfgfg
5/22/2014 03:54:07 pm

Reply
12/23/2015 12:20:24 am

In Android, I am facing many time convert Bitmap to String and String to Bitmap. When send or receive Bitmap to server and storing Image in database.

Reply
nbjk
7/8/2016 03:03:20 am

Reply



Leave a Reply.

    Author

    "IF you you don't have time  for fitness  then save time for sickness tomorrow"

    Android Tutorial

    Archives

    October 2012

    Categories

    All
    Date Conversation
    String To Bitmap And Vice Versa