Out of memory when encoding file to base64

前端 未结 8 598
自闭症患者
自闭症患者 2020-11-30 03:46

Using Base64 from Apache commons

public byte[] encode(File file) throws FileNotFoundException, IOException {
        byte[] encoded;
        try (FileInputSt         


        
8条回答
  •  不知归路
    2020-11-30 04:00

    This is best code to upload image of more size

    bitmap=Bitmap.createScaledBitmap(bitmap, 100, 100, true);
    
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream); //compress to which format you want.
    byte [] byte_arr = stream.toByteArray();  
    String image_str = Base64.encodeBytes(byte_arr);
    

提交回复
热议问题