Search This Blog

Showing posts with label String. Show all posts
Showing posts with label String. Show all posts

Saturday, 17 March 2012

How to convert string to bitmap and Bitmap to string


In android, Normally we send and receive data in the form of]string.So if we have image in the Bitmap form then we can not send it to server.So here i made a simple function that you need pass bitmap and it will return a string
     /**
       * @param bitmap
       * @return converting bitmap and return a string
       */
       public String BitMapToString(Bitmap bitmap){
            ByteArrayOutputStream baos=new  ByteArrayOutputStream();
            bitmap.compress(Bitmap.CompressFormat.PNG,100, baos);
            byte [] b=baos.toByteArray();
            String temp=Base64.encodeToString(b, Base64.DEFAULT);
            return temp;
      }


Android News and source code