-1

I make canvas view which I want to send in server using retrofit library. I get canvas view in bitmap format. Now I want to convert bitmap to file format so that I can upload in server in file format.

1
  • convert bitmap to base64 and upload it to server Commented Jul 10, 2018 at 7:34

2 Answers 2

0
File file = new File(context.getCacheDir(), filename); file.createNewFile(); /* Convert bitmap to byte array */ Bitmap bitmap = bitmap; //bitmap is your bitmap file which you want to convert ByteArrayOutputStream bos = new ByteArrayOutputStream(); bitmap.compress(CompressFormat.PNG, 0 , bos); byte[] bitmapdata = bos.toByteArray(); /* write the bytes in file */ FileOutputStream fos = new FileOutputStream(file); fos.write(bitmapdata); fos.flush(); fos.close(); 

Always close and flush the FileOutputStream.

Sign up to request clarification or add additional context in comments.

2 Comments

FileOutputStream require string values
Read file as a string. for this visit the link stackoverflow.com/questions/12910503/read-file-as-string
0

Convert ua bitmap to base64 String like below and send it using string

 public static String bitmapToBase64(Bitmap image, Bitmap.CompressFormat compressFormat, int quality)//u can pass 100 in quality or any integer { ByteArrayOutputStream byteArrayOS = new ByteArrayOutputStream(); image.compress(compressFormat, quality, byteArrayOS); return Base64.encodeToString(byteArrayOS.toByteArray(), Base64.DEFAULT); } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.