OutOfMemoryError while decoding and encoding Base64 String into Bitmap

前端 未结 7 1988
你的背包
你的背包 2020-12-14 14:49

I\'m trying to decode and encode a Bitmap image. On some devices it runs perfectly while on others it\'s not. I\'m uploading Bas

相关标签:
7条回答
  • 2020-12-14 15:39

    Try With this pseudo code: Let me know if you have any questions

    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);
    
    0 讨论(0)
提交回复
热议问题