how to convert an image into base64 string

前端 未结 5 872
醉梦人生
醉梦人生 2020-12-19 04:09

I want to convert image to base 64 encode to string. from that to send to server with oma_status-icon xml format.

but I am getting unsupported encodin

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-19 04:21

    try below code

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bm.compress(Bitmap.CompressFormat.JPEG, 100, baos);
    byte b [] = baos.toByteArray();
    String base64String = Base64.encodeToString(b, Base64.DEFAULT);
    

    Dont forget to import android.util.Base64;

提交回复
热议问题