title: Encode facebook url image to BASE 64 string in android
body: <p>Let me explain my problem.</p>
  
  <p>I am trying to set Facebook profile image in app Imageview some thing like this ..</p>
  
  <pre><code>// Getting Facebook URL image and converting same to bitmap
  Bitmap mIcon1;
  
  
  URL img_value = new URL("http://graph.facebook.com/"+ userProfileID +"/picture?type=square");
  BitmapFactory.Options options = new BitmapFactory.Options();
  mIcon1 = BitmapFactory.decodeStream(img_value.openConnection().getInputStream(), null, options);
  </code></pre>
  
  <p>Then after ..</p>
  
  <pre><code>// I am setting bitmap to imageview .. some thing like ..
  
  if(mIcon1!=null) {
     user_picture.setImageBitmap(mIcon1);
  }
  </code></pre>
  
  <p>Up to here it is working great ... </p>
  
  <p>Now I need to save that Facebook Profile image into my DB located at server ...  </p>
  
  <p>I am performing that stuff some thing like ..</p>
  
  <pre><code>// Created a method for encoding ..
   public static String encodeTobase64(Bitmap image)
    {
        Bitmap immagex=image;
        ByteArrayOutputStream baos = new ByteArrayOutputStream();  
        immagex.compress(Bitmap.CompressFormat.JPEG, 100, baos);
        byte[] b = baos.toByteArray();
        String imageEncoded = Base64.encodeToString(b,Base64.DEFAULT);
  
        Log.e("LOOK", imageEncoded);
        return imageEncoded;
    }
  
  
  // Now trying to use this method to get encoded BASE 64 image in string ..
  
  String final_image = encodeTobase64(mIcon1);
  </code></pre>
  
  <p>Now when I try to send this string to my server then at server end I am recieving broken link ... Instead I must say that it's not working ..</p>
  
  <p><strong>I need to perform two of stuff</strong></p>
  
  <ul>
  <li>Encode Facebook profile image to Encoded BASE 64 string so as to send same to server.</li>
  <li>Get type of image (i.e.  PNG/ JPG ... ) or compress and send that image in one specific format. </li>
  </ul>
  
  <p>Looking forward for any suggestion on this.
  Thanks! </p>