Image encoding and Decoding using Base64 in android application

后端 未结 2 1516
忘掉有多难
忘掉有多难 2021-01-06 12:32

In my application I have faced a small issue in encoding and decoding images to String and pass it to web service. After getting the bitmap image, I convert it into

2条回答
  •  孤独总比滥情好
    2021-01-06 13:14

    Try My Below Sample Code Of Project

    Bitmap bmp = (Bitmap) data.getExtras().get("data");
    
            img.setImageBitmap(bmp);
            btnadd.requestFocus();
    
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            bmp.compress(Bitmap.CompressFormat.JPEG, 100, baos);
            byte[] b = baos.toByteArray();
            encodedImageString = Base64.encodeToString(b, Base64.DEFAULT);
    
            byte[] bytarray = Base64.decode(encodedImageString, Base64.DEFAULT);
            Bitmap bmimage = BitmapFactory.decodeByteArray(bytarray, 0,
                    bytarray.length);
    

提交回复
热议问题