isama92

Java Bitmap-String Conversion

Apr 10th, 2017
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.65 KB | None | 0 0
  1.     private String BitmapToString(Bitmap bitmap){
  2.         ByteArrayOutputStream baos = new ByteArrayOutputStream();
  3.         bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
  4.         byte[] b = baos.toByteArray();
  5.         return Base64.encodeToString(b, Base64.DEFAULT);
  6.     }
  7.  
  8.     public Bitmap StringToBitmap(String encodedString){
  9.         try{
  10.             byte[] encodeByte = Base64.decode(encodedString, Base64.DEFAULT);
  11.             Bitmap bitmap = BitmapFactory.decodeByteArray(encodeByte, 0, encodeByte.length);
  12.             return bitmap;
  13.         } catch(Exception e){
  14.             e.getMessage();
  15.             return null;
  16.         }
  17.     }
Advertisement
Add Comment
Please, Sign In to add comment